3
<?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?

5
  • 1
    It's possible if it has the same signature. Your b.bar accepts $a, while a.bar does not, which is the source of the fatal error. Commented Jul 19, 2012 at 14:07
  • @Yoshi what is the point if it has the same signature. What is the point altogether. Commented Jul 19, 2012 at 14:07
  • 1
    @Esailija That's a thing you'll have to ask the php devs. I just pointed out the error, that tripped me often enough myself ;) Commented Jul 19, 2012 at 14:08
  • @Esailija You are still able to implement the same function in another way. You may also emulate overloading using func_get_args() Commented Jul 19, 2012 at 14:13
  • @yoshi i know the reason of the error. i want to know if it is possible or not in this way or any other way to do it. Commented Jul 19, 2012 at 14:18

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

The Can't inherit... error is a php bug, fixed in 5.3.9.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.