Bug #80055 [Opn->Ver]: Abstract trait methods returning "self" cannot be fulfilled by traits

From: Date: Fri, 04 Sep 2020 07:28:30 +0000
Subject: Bug #80055 [Opn->Ver]: Abstract trait methods returning "self" cannot be fulfilled by traits
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-228873@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80055&edit=1 ID: 80055 Updated by: nikic@php.net Reported by: dusk at woofle dot net Summary: Abstract trait methods returning "self" cannot be fulfilled by traits -Status: Open +Status: Verified Type: Bug Package: Class/Object related Operating System: any PHP Version: 7.4.10 Block user comment: N Private report: N New Comment: Also the case on PHP 8: https://3v4l.org/Go6WO Previous Comments: ------------------------------------------------------------------------ [2020-09-04 07:02:48] dusk at woofle dot net Description: ------------ If a concrete method implemented by a trait is declared as returning "self", it is considered incompatible with an abstract declaration of that method in another trait. Test script: --------------- trait AbstractTrait { abstract public function selfReturner() : self; } trait ConcreteTrait { public function selfReturner() : self { return $this; } } class Test { use AbstractTrait; use ConcreteTrait; } Expected result: ---------------- The AbstractTrait trait should be satisfied by the implementation provided by ConcreteTrait. Actual result: -------------- Fatal error: Declaration of ConcreteTrait::selfReturner(): ConcreteTrait must be compatible with AbstractTrait::selfReturner(): AbstractTrait ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80055&edit=1

« previous php.bugs (#228873) next »