Bug #69180 [Ver->Csd]: Reflection does not honor trait conflict resolution / method aliasing

From: Date: Tue, 03 Mar 2020 10:57:00 +0000
Subject: Bug #69180 [Ver->Csd]: Reflection does not honor trait conflict resolution / method aliasing
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225856@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69180&edit=1 ID: 69180 Updated by: nikic@php.net Reported by: sebastian@php.net Summary: Reflection does not honor trait conflict resolution / method aliasing -Status: Verified +Status: Closed Type: Bug Package: Reflection related Operating System: Irrelevant PHP Version: 5.6.6 Assigned To: nikic Block user comment: N Private report: N New Comment: Fixed by https://github.com/php/php-src/commit/53efa1b0c69b463ea9d3606d828c036129f2dec9. Previous Comments: ------------------------------------------------------------------------ [2020-03-02 12:16:15] nikic@php.net The following pull request has been associated: Patch Name: Fix bug #69180 (Reflection does not honor trait conflict resolution / method aliasing) On GitHub: https://github.com/php/php-src/pull/5226 Patch: https://github.com/php/php-src/pull/5226.patch ------------------------------------------------------------------------ [2020-03-02 11:26:06] nikic@php.net I think the right way to fix this is to actually give aliased methods the right name, rather than trying to reverse-engineer it in various reflection APIs. In principle this is possible, we just need to make the function name owned independently of the op array refcount. But making this work with opcache is not entirely simple. ------------------------------------------------------------------------ [2015-06-02 13:35:17] 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 ------------------------------------------------------------------------ [2015-03-04 08:05:17] 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" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69180&edit=1

« previous php.bugs (#225856) next »