Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php interface method overriding

<?php
interface a {
    public function bar();
}
interface b extends a {
    public function foo();
    public function bar($a);
}

?>

It is showing a fatal error of signature missmatch in method. is not it possible to override a method of interface in php?

like image 561
varuog Avatar asked Apr 14 '26 01:04

varuog


1 Answers

You're getting the signature mismatch error because the two bar functions aren't compatible.

You can fix it by changing the interface to

interface b extends a {
    public function foo();
    public function bar($a = null);
}

Although this might not be a complete solution, as you will now get a Can't inherit abstract function error.

like image 186
Jrgns Avatar answered Apr 15 '26 13:04

Jrgns



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!