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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
28 - 16 = ?
Subscribe to this entry?

 
 [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: Tue Apr 16 07:01:29 2024 UTC