|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-12-20 22:45 UTC] helly@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 05 08:00:02 2025 UTC |
Description: ------------ A typical OOP use of the Command Pattern (design pattern) is to have an interface, an abstract class that leaves the interface methods as abstract, then a subclass that implements the methods (now named in both interface and abstract class). PHP5 wrongly complains that an interface method can not be implemented as an abstract method in an abstract class. As a side-effect, it seems NOT to complain when an abstract class does *not* implement the methods named in its interface. Reproduce code: --------------- #1 - Abstract class not implementing interface method - WORKS but should not! interface MyInterface { function play(); } abstract class MyAbstractClass implements MyInterface { } #2 - Abstract class implementing interface method as abstract - DOES NOT WORK but should interface MyInterface { function play(); } abstract class MyAbstractClass implements MyInterface { abstract function play(); } #3 - Normal OO use of interface and abstract class, but DOES NOT WORK interface MyInterface { function play(); } abstract class MyAbstractClass implements MyInterface { abstract function play(); } class MyClass extends MyAbstractClass { function play() { print "Playing\n"; } } $x = new MyClass; $x->play(); Expected result: ---------------- #1 - Class (even if Abstract class) not implementing interface method should fail. #2 - Abstract class that implements interface method as abstract method should not fail (expecting that actual method would come in subclass) #3 - Normal OO use of interface and abstract class should let subclass use of that interface/abstract method work. Actual result: -------------- #1 - No error #2 - Fatal error: Can't inherit abstract function MyInterface::play() (previously declared abstract in MyAbstractClass) #3 - Fatal error: Can't inherit abstract function MyInterface::play() (previously declared abstract in MyAbstractClass)