php.net |  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
Votes:4
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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dagguh at gmail dot com
New email:
PHP Version: OS:

 

 [2012-10-29 11:23 UTC] dagguh at gmail dot com
Description:
------------
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

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-01-03 16:17 UTC] kassner@php.net
Reproducible on PHP 5.5.20.
 [2017-05-24 15:44 UTC] nikic@php.net
-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: Thu Nov 21 12:01:29 2024 UTC