#43277 [NEW]: Interfaces behaving too much like classes

From: Date: Tue, 13 Nov 2007 12:19:47 +0000
Subject: #43277 [NEW]: Interfaces behaving too much like classes
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-119623@lists.php.net to get a copy of this message
From: krister dot karlstrom at arcada dot fi Operating system: Linux/Slackware PHP version: 5.2.5 PHP Bug Type: Class/Object related Bug description: Interfaces behaving too much like classes 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 -- Edit bug report at http://bugs.php.net/?id=43277&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=43277&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=43277&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=43277&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=43277&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=43277&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=43277&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=43277&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=43277&r=needscript Try newer version: http://bugs.php.net/fix.php?id=43277&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=43277&r=support Expected behavior: http://bugs.php.net/fix.php?id=43277&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=43277&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=43277&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=43277&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43277&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=43277&r=dst IIS Stability: http://bugs.php.net/fix.php?id=43277&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=43277&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=43277&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=43277&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=43277&r=mysqlcfg

« previous php.bugs (#119623) next »