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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 09:01:28 2024 UTC