php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73152 Hint of return type in PHP works unexpected way.
Submitted: 2016-09-23 16:02 UTC Modified: 2016-09-23 18:08 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: roman at litgroup dot ru Assigned: cmb (profile)
Status: Duplicate Package: *General Issues
PHP Version: 7.0.11 OS: Linux
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: roman at litgroup dot ru
New email:
PHP Version: OS:

 

 [2016-09-23 16:02 UTC] roman at litgroup dot ru
Description:
------------
Hint of return type in PHP works unexpected way.
It's not possible to change hint of return type to a more concrete subtype.

Test script:
---------------
interface Person {/* _ */}

interface PersonFactory
{
    public function createPerson(): Person;
}

class Customer implements Person {/* _ */}

class CustomerFactory implements PersonFactory
{
    public function createPerson(): Customer // PHP Fatal error:
    {                                        // Declaration of CustomerFactory::createPerson(): Customer
        return new Customer();               // must be compatible with PersonFactory::createPerson(): Person
    }
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-09-23 18:08 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2016-09-23 18:08 UTC] cmb@php.net
Duplicate of feature request #72442.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 04:01:28 2024 UTC