|  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
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:
From: dusk at woofle dot net
New email:
PHP Version: OS:


 [2020-09-04 07:02 UTC] dusk at woofle dot net
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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-09-04 07:28 UTC]
-Status: Open +Status: Verified
 [2020-09-04 07:28 UTC]
Also the case on PHP 8:
 [2020-10-15 12:24 UTC]
Automatic comment on behalf of
Log: Fix bug #80055
 [2020-10-15 12:24 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jul 14 11:01:28 2024 UTC