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

From: Date: Sun, 04 Sep 2016 10:10:08 +0000
Subject: Req #73010 [Opn]: Can't override interfaces' method return type with its subtypes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-203779@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: requinix@php.net Reported by: alan dot bem at gmail dot com Summary: Can't override interfaces' method return type with its subtypes Status: Open Type: Feature/Change Request Package: Class/Object related PHP Version: 7.1.0RC1 Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [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 (#203779) next »