php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #76011 Sub class should be allowed to change the specificity of return type
Submitted: 2018-02-26 11:48 UTC Modified: 2018-02-26 11:55 UTC
From: ramouixn at pokemail dot net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.2.2 OS:
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ramouixn at pokemail dot net
New email:
PHP Version: OS:

 

 [2018-02-26 11:48 UTC] ramouixn at pokemail dot net
Description:
------------
Greetings,

I believe the following should be allowed.

class Animal {}

class Cat extends Animal {}

class My1 {
    public function getAnimal () : Animal {}
}

class My2 extends My1 {
    public function getAnimal () : Cat {}
}

Because Cat is a Animal and thus compatible with the inherited signature.

Thanks in advance.

Expected result:
----------------
No errors

Actual result:
--------------
Compile error

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-02-26 11:52 UTC] requinix@php.net
-Status: Open +Status: Duplicate
 [2018-02-26 11:52 UTC] requinix@php.net
It is allowed by LSP but PHP does not support it yet because of technical limitations.
 [2018-02-26 11:52 UTC] kelunik@php.net
-Status: Duplicate +Status: Open -Type: Bug +Type: Feature/Change Request
 [2018-02-26 11:53 UTC] kelunik@php.net
-Status: Open +Status: Duplicate
 [2018-02-26 11:53 UTC] kelunik@php.net
Stupid bug tracker doesn't detect conflicts on changes...
 [2018-02-26 11:55 UTC] krakjoe@php.net
-Status: Duplicate +Status: Not a bug
 [2018-02-26 11:55 UTC] krakjoe@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 11:01:32 2025 UTC