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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

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 Mar 28 20:01:28 2024 UTC