From: dagguh at gmail dot com Operating system: Irrelevant PHP version: 5.3.18 Package: *General Issues Bug Type: Feature/Change Request Bug description:Overriding method with an abstract method
Description: ------------ In Java you can override a method with an abstract one, but in PHP it results in: Fatal error: Cannot make non abstract method IdentifiableExceptionTests::getSystemUnderTest() abstract in class RestResponseExceptionTests in xxx on line yyy Test script: --------------- class HttpNotFoundException extends RestResponseException { public function getHttpStatusCode() { // ... } } abstract class RestResponseException extends IdentifiableException { public abstract function getHttpStatusCode(); } class IdentifiableException extends Exception { // ... } // ----------------------- and here come the tests: class HttpNotFoundExceptionTests extends RestResponseExceptionTests { protected function getSystemUnderTest() { return new HttpNotFoundException(); } // ... tests logic specific to HttpNotFoundException } class RestResponseExceptionTests extends IdentifiableExceptionTests { /** * @return RestResponseException */ protected abstract function getSystemUnderTest(); // ... tests specific for RestResponseException, even though it is an abstract class, it has some logic implemented and tests for that portion of logic are specified here. It is important to note that while getSystemUnderTest() method in IdentifiableExceptionTests expects IdentifiableException, in RestResponseExceptionTests it expects RestResponseException, which is a proper subclass of IdentifiableException } class IdentifiableExceptionTests extends PHPUnit_Framework_TestCase { /** * @return IdentifiableException */ protected function getSystemUnderTest() { return new IdentifiableException(); } //... tests IdentifiableException logic } Expected result: ---------------- I expect this code to work. It works in Java, so why cannot it work in PHP? Actual result: -------------- Fatal error: Cannot make non abstract method IdentifiableExceptionTests::getSystemUnderTest() abstract in class RestResponseExceptionTests in xxx on line yyy -- Edit bug report at https://bugs.php.net/bug.php?id=63371&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=63371&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=63371&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=63371&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=63371&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=63371&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=63371&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=63371&r=needscript Try newer version: https://bugs.php.net/fix.php?id=63371&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=63371&r=support Expected behavior: https://bugs.php.net/fix.php?id=63371&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=63371&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=63371&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=63371&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=63371&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=63371&r=dst IIS Stability: https://bugs.php.net/fix.php?id=63371&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=63371&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=63371&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=63371&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=63371&r=mysqlcfg