Req #73010 [Opn->Csd]: Can't override interfaces' method return type with its subtypes

From: Date: Thu, 05 Mar 2020 17:58:51 +0000
Subject: Req #73010 [Opn->Csd]: Can't override interfaces' method return type with its subtypes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225916@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73010&edit=1 ID: 73010 Updated by: nikic@php.net Reported by: alan dot bem at gmail dot com Summary: Can't override interfaces' method return type with its subtypes -Status: Open +Status: Closed Type: Feature/Change Request Package: Class/Object related PHP Version: 7.1.0RC1 -Assigned To: +Assigned To: nikic Block user comment: N Private report: N New Comment: This is supported as of PHP 7.4. Previous Comments: ------------------------------------------------------------------------ [2019-02-15 03:38:30] carusogabriel@php.net I believe this is related to https://wiki.php.net/rfc/covariant-returns-and-contravariant-parameters. ------------------------------------------------------------------------ [2017-02-26 12:10:15] nikic@php.net Related To: Bug #74169 ------------------------------------------------------------------------ [2016-09-04 10:10:06] 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. ------------------------------------------------------------------------ [2016-09-04 09:53:26] 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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=73010&edit=1

« previous php.bugs (#225916) next »