|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-11-20 19:01 UTC] helly@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 07:00:01 2025 UTC |
Description: ------------ I found this "weird" mix-up of the behaviour of interfaces and abstract classes. I think that you should be able to always implement an interface, regardless of how and where some of the implemented methods where declared or defined. The only thing that should matter is that the declared class defines all the methods that the interface requires. The error message from PHP says that it can't inherit the method Test::foo() - an implementation of an interface has nothing to do with inheritance in classes in the OO-model. It shouldn't even try to "inherit" the methods of the interface, just check that the defined class implements all of the required methods. Reproduce code: --------------- <?php interface Test { public function foo(); } abstract class Bar { public abstract function foo(); } class FooBar extends Bar implements Test { public function foo() { echo "Hello!"; } } ?> Expected result: ---------------- I expect this to raise no error, because the class FooBar nicely defines and implements the method foo(), as the interface Test defines. Actual result: -------------- [error] PHP Fatal error: Can't inherit abstract function Test::foo() (previously declared abstract in Bar) in /var/www/asta.arcada.fi/beta/foobar.php on line 13