|  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.
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-2023 The PHP Group
All rights reserved.
Last updated: Sat Sep 23 04:01:24 2023 UTC