php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75689 Wrong function pointer when using functions from trait
Submitted: 2017-12-14 18:04 UTC Modified: 2017-12-14 21:47 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: andrey at phpteam dot pro Assigned:
Status: Duplicate Package: Class/Object related
PHP Version: 7.1.11 OS: MacOs
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:
11 + 33 = ?
Subscribe to this entry?

 
 [2017-12-14 18:04 UTC] andrey at phpteam dot pro
Description:
------------
PHP 7.1.11
Using a function from trait ends up with using wrong function. 



Test script:
---------------
<?php

trait traitA {
    public function __invoke() {
        echo "traitA\n";
    }
}


trait traitB {
    public function __invoke() {
        echo "traitB\n";
    }
}

class JustAClass
{
    use traitA {
        __invoke as protected hocus;
    }

    use traitB {
        __invoke as protected pocus;
    }

    public function __invoke()
    {
        $this->hocus();
        $this->pocus();
    }

}

$instance = new JustAClass();
$instance();

Expected result:
----------------
traitA
traitB

Actual result:
--------------
traitA
traitA

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-12-14 18:15 UTC] andrey at phpteam dot pro
Or I would it expect to complain that 2nd invoke wasn't imported because of name collision. But that not what you prefer when you giving detail reqirements on under which name function should be accessible.
 [2017-12-14 18:24 UTC] andrey at phpteam dot pro
-PHP Version: 7.2.0 +PHP Version: 7.1.11
 [2017-12-14 18:24 UTC] andrey at phpteam dot pro
Just edit this to put correct version
 [2017-12-14 21:47 UTC] requinix@php.net
-Status: Open +Status: Duplicate
 [2017-12-14 21:47 UTC] requinix@php.net
Duplicate of bug #74872
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 09:01:29 2024 UTC