php.net |  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: 2018-07-05 18:02 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: levim@php.net Assigned: levim (profile)
Status: Assigned 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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: levim@php.net
New email:
PHP Version: OS:

 

 [2018-07-04 23:32 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-07-04 23:32 UTC] levim@php.net
-Assigned To: +Assigned To: levim
 [2018-07-04 23:46 UTC] 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-05 18:02 UTC] 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.
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Thu Oct 18 05:01:25 2018 UTC