|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63384 Cannot override an abstract method with an abstract method
Submitted: 2012-10-29 11:23 UTC Modified: 2017-05-24 15:44 UTC
Avg. Score:4.0 ± 1.2
Reproduced:3 of 4 (75.0%)
Same Version:3 (100.0%)
Same OS:3 (100.0%)
From: dagguh at gmail dot com Assigned: nikic (profile)
Status: Closed Package: Class/Object related
PHP Version: 5.3.18 OS: Irrelevant
Private report: No CVE-ID: None
 [2012-10-29 11:23 UTC] dagguh at gmail dot com
It is impossible to override an abstract method with another abstract method.
This is useful if you are trying to indicate (to both IDE and other developers) 
that the overriden method returns type is expected to be a subclass of the 
inherited method return type.

PS. Java allows it and it is generally a more restrictive language than PHP.

Test script:
abstract class RuntimeExceptionReporter extends ExceptionReporter {

     * @return RuntimeException
    public abstract function getExceptionToReport();

    // ... some operations specific to RuntimeException


abstract class ExceptionReporter {

     * @return Exception
    public abstract function getExceptionToReport();

    // ... some operations on an Exception


Expected result:
Correct inheritance

Actual result:
Fatal error: Can't inherit abstract function 
ExceptionReporter::getExceptionToReport() (previously declared abstract in 
RuntimeExceptionReporter) in xxx on line yyy


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-01-03 16:17 UTC]
Reproducible on PHP 5.5.20.
 [2017-05-24 15:44 UTC]
-Status: Open +Status: Closed -Type: Bug +Type: Feature/Change Request -Assigned To: +Assigned To: nikic
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 21 08:01:31 2024 UTC