Bug #76581 [Asn->Csd]: Multi-level parent/self does not get correctly resolved

From: Date: Thu, 25 Jun 2020 08:16:55 +0000
Subject: Bug #76581 [Asn->Csd]: Multi-level parent/self does not get correctly resolved
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-227644@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76581&edit=1 ID: 76581 Updated by: nikic@php.net Reported by: levim@php.net Summary: Multi-level parent/self does not get correctly resolved -Status: Assigned +Status: Closed Type: Bug Package: Class/Object related PHP Version: 7.3.0alpha2 Assigned To: levim Block user comment: N Private report: N New Comment: Behavior since PHP 7.4 is: Deprecated: Cannot use "parent" when current class scope has no parent Fatal error: Could not check compatibility between B::m(B $s): parent and A::m(B $s): A, because class parent is not available I think that's pretty clear. And in PHP 8: Fatal error: Cannot use "parent" when current class scope has no parent Previous Comments: ------------------------------------------------------------------------ [2018-07-05 18:02:53] kalle@php.net I agree that the decl of B::m(B $s) : parent should error out if B does not extend another class, the decl of C::m(parent $s) : A makes sense, but the error should happen earlier to show the real issue. ------------------------------------------------------------------------ [2018-07-04 23:46:22] levim@php.net Looking at this more I think perhaps the real bug is when defining B::m(): parent that it doesn't error. In most (all?) other contexts parent refers to class inheritance, not interface inheritance. ------------------------------------------------------------------------ [2018-07-04 23:32:38] levim@php.net Description: ------------ This affects all PHP 7.X versions to date (7.3 alpha 1). Test script: --------------- https://3v4l.org/Od72V <?php interface A { function m(B $s): self; } class B implements A { function m(self $s): parent { return $this; } } class C extends B { function m(parent $s): A { return $this; } } ?> Expected result: ---------------- No error. Actual result: -------------- Fatal error: Declaration of C::m(B $s): A must be compatible with B::m(B $s): parent in % on line %d ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76581&edit=1

« previous php.bugs (#227644) next »