php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80055 Abstract trait methods returning "self" cannot be fulfilled by traits
Submitted: 2020-09-04 07:02 UTC Modified: 2020-09-04 07:28 UTC
From: dusk at woofle dot net Assigned:
Status: Closed Package: Class/Object related
PHP Version: 7.4.10 OS: any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dusk at woofle dot net
New email:
PHP Version: OS:

 

 [2020-09-04 07:02 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-09-04 07:28 UTC] nikic@php.net
-Status: Open +Status: Verified
 [2020-09-04 07:28 UTC] nikic@php.net
Also the case on PHP 8: https://3v4l.org/Go6WO
 [2020-10-15 12:24 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=4ece62fba9ff4ea5e500a329ae2c349f91771ff8
Log: Fix bug #80055
 [2020-10-15 12:24 UTC] nikic@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 08:01:28 2024 UTC