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 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

Pull Requests

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: Thu Nov 21 11:01:29 2024 UTC