|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #73010 Can't override interfaces' method return type with its subtypes
Submitted: 2016-09-04 09:53 UTC Modified: 2020-03-05 17:58 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: alan dot bem at gmail dot com Assigned: nikic (profile)
Status: Closed Package: Class/Object related
PHP Version: 7.1.0RC1 OS:
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:
44 + 46 = ?
Subscribe to this entry?

 [2016-09-04 09:53 UTC] alan dot bem at gmail dot com
Affected PHP versions: 7.0.0 - 7.1.0beta3

When implementing interfaces, it is impossible to override return types declarations with their (return types) subtypes/implementations although it is perfectly fine with LSP.

Test script:

Now I get error: "Fatal error: Declaration of CustomerFactory::create(): Customer must be compatible with AggregateRootFactory::create(): AggregateRoot in /file/path on line 15"

I expect: Customer type is implementation of AggregateRoot and it should work perfectly fine.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-09-04 10:10 UTC]
While allowed by LSP, return types are deliberately invariant due to implementation issues. That may change in the future.

This is a legitimate request so I'm not marking this as NAB/Wontfix/Suspended, but currently there are no plans to add support for covariance.
 [2020-03-05 17:58 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2020-03-05 17:58 UTC]
This is supported as of PHP 7.4.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 19:01:30 2024 UTC