php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69180 Reflection does not honor trait conflict resolution / method aliasing
Submitted: 2015-03-04 08:05 UTC Modified: -
From: sebastian@php.net Assigned:
Status: Open Package: Reflection related
PHP Version: 5.6.6 OS: Irrelevant
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: sebastian@php.net
New email:
PHP Version: OS:

 

 [2015-03-04 08:05 UTC] sebastian@php.net
Description:
------------
The Reflection API does not honor the method aliasing / conflict resolution mechanism for traits.

Test script:
---------------
<?php
trait T1
{
    public function foo()
    {
    }
}

trait T2
{
    use T1 { foo as bar; }

    public function foo()
    {
    }
}


class C
{
    use T2;
}

$class = new ReflectionClass('C');

foreach ($class->getMethods() as $method) {
    var_dump($method->getName());
}


Expected result:
----------------
string(3) "bar"
string(3) "foo"


Actual result:
--------------
string(3) "foo"
string(3) "foo"


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-02 13:35 UTC] jpauli@php.net
mmmm not easy.

This is because trait aliases are only resolved in a one-depth dimension.

If class Foo uses trait T1, class Foo will be assigned T1 as trait_aliases.
But if then T1 uses T2, Foo will not be assigned T2 as one of its own trait_aliases, T2 will be however a trait_alias of T1, as expected.

Reflection uses trait_aliases to get method names, thus this bug report.

This ugly patch (https://github.com/jpauli/php-src/tree/69180) changes that, and uses the hash_key that owns the resolved name directly, however, this is case insensitive, and thus breaks another test.

This is also a quick and dirty patch, I think we should rework the traits deeply, but that's not an easy task knowing how dirty they've been implemented :-(

https://github.com/jpauli/php-src/tree/69180
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Sep 20 07:01:26 2019 UTC