php.net |  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
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: 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
Description:
------------
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:
---------------
https://3v4l.org/MgU9b

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.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-09-04 10:10 UTC] requinix@php.net
While allowed by LSP, return types are deliberately invariant due to implementation issues. That may change in the future.
https://wiki.php.net/rfc/return_types#variance_and_signature_validation

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: Tue Mar 26 14:01:27 2019 UTC