|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2012-10-26 17:23 UTC] hanskrentel at yahoo dot de
[2012-10-26 18:10 UTC] dagguh at gmail dot com
[2021-08-06 16:03 UTC] cmb@php.net
-Status: Open
+Status: Suspended
[2021-08-06 16:03 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 10:00:01 2025 UTC |
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