|  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: 2016-09-04 10:10 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:
Status: Open Package: Class/Object related
PHP Version: 7.1.0RC1 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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.
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Oct 23 21:01:33 2019 UTC