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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Fri Apr 19 01:01:28 2024 UTC