Bug #78517 [Opn->Csd]: Unable to connect two libraries where developer wants to return typehint

From: Date: Mon, 09 Sep 2019 10:26:45 +0000
Subject: Bug #78517 [Opn->Csd]: Unable to connect two libraries where developer wants to return typehint
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-222646@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78517&edit=1 ID: 78517 Updated by: nikic@php.net Reported by: 6562680 at gmail dot com Summary: Unable to connect two libraries where developer wants to return typehint -Status: Open +Status: Closed Type: Bug Package: Reflection related Operating System: Win10 PHP Version: 7.2.22 -Assigned To: +Assigned To: nikic Block user comment: N Private report: N New Comment: This is called "covariant return types" and will be supported in PHP 7.4. Previous Comments: ------------------------------------------------------------------------ [2019-09-09 10:24:04] 6562680 at gmail dot com ps. 5*. usually we copy library interface to project like laws copies contracts or like businessman copy job offer contract ------------------------------------------------------------------------ [2019-09-09 10:23:03] 6562680 at gmail dot com Description: ------------ Maybe i understand interfaces incorrect but i think that we: 1. Create library 2. Create interface inside library 3. Upload library somewhere (composer) 4. Require library to project 5. Create interface in project for library wrapper 6. Will check our own interface inside project - library should match both interfaces and return instance that match both interfaces But sometimes we need to extend library or just change some functions using extend. We want to change return type to our own interface and we cant, because return checker wont check interface, just compare strings Test script: --------------- <?php interface iA {}; class A implements iA { public function test() : self // public function test() : A // or maybe direct class // public function test() : iA // or maybe interface { return true; } } interface iB {}; class B extends A implements iB { // public function test() : self // wtf? incorrect // public function test() : B // wtf? incorrect // public function test() : iA // works but requires use everywhere public function test() : A // works but requires use everywhere { return true; } } var_dump(new B); ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78517&edit=1

« previous php.bugs (#222646) next »