|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76581 Multi-level parent/self does not get correctly resolved
Submitted: 2018-07-04 23:32 UTC Modified: 2020-06-25 08:16 UTC
Avg. Score:4.0 ± 1.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: Assigned: levim (profile)
Status: Closed Package: Class/Object related
PHP Version: 7.3.0alpha2 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
New email:
PHP Version: OS:


 [2018-07-04 23:32 UTC]
This affects all PHP 7.X versions to date (7.3 alpha 1).

Test script:


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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-07-04 23:32 UTC]
-Assigned To: +Assigned To: levim
 [2018-07-04 23:46 UTC]
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-05 18:02 UTC]
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.
 [2020-06-25 08:16 UTC]
-Status: Assigned +Status: Closed
 [2020-06-25 08:16 UTC]
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
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 26 12:01:29 2024 UTC