Req #63371 [Com]: Overriding method with an abstract method
| From: | hanskrentel at yahoo dot de | Date: | Fri, 26 Oct 2012 17:23:52 +0000 |
| Subject: | Req #63371 [Com]: Overriding method with an abstract method | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-174358@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63371&edit=1
ID: 63371
Comment by: hanskrentel at yahoo dot de
Reported by: dagguh at gmail dot com
Summary: Overriding method with an abstract method
Status: Open
Type: Feature/Change Request
Package: *General Issues
Operating System: Irrelevant
PHP Version: 5.3.18
Block user comment: N
Private report: N
New Comment:
> It works in Java, so why cannot it work in PHP?
Because PHP is PHP and Java is Java. So where to file the bug-report? Shouldn't it
be reported as a bug at Java, because Java doesn't do it like PHP?
Previous Comments:
------------------------------------------------------------------------
[2012-10-26 17:16:30] dagguh at gmail dot com
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 this bug report at https://bugs.php.net/bug.php?id=63371&edit=1