|  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
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 Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
31 + 34 = ?
Subscribe to this entry?

 [2016-09-23 16:02 UTC] roman at litgroup dot ru
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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-09-23 18:08 UTC]
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2016-09-23 18:08 UTC]
Duplicate of feature request #72442.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 20 01:01:32 2024 UTC