PHP :: Bug #63399 :: ReflectionClass::getTraitAliases() incorrectly resolves traitnames

Bug #63399 ReflectionClass::getTraitAliases() incorrectly resolves traitnames
Submitted: 2012-10-30 14:19 UTC Modified: 2012-10-30 15:09 UTC
From: r dot wilczek at web-appz dot de Assigned: laruence (profile)
Status: Closed Package: Reflection related
PHP Version: 5.4.7RC1 OS: Linux x86_64
Private report: No CVE-ID: None

 [2012-10-30 14:19 UTC] r dot wilczek at web-appz dot de

Description:
------------
When aliasing an importing traitmethod without explicitely declaring the trait's name, ReflectionClass::getTraitAliases() renders the traitname as '(null)'.

The method should render the correct traitname, as if the aliasing had been done using the full qualifier.

(Actually, my PHP-version is 5.4.7, not 5.4.7RC1)

Test script:
---------------
trait MyTrait
{
    public function run() {}
}

class MyClass
{
    use MyTrait {
        run as execute;
    }
}

var_export((new \ReflectionClass('MyClass'))->getTraitAliases());

Expected result:
----------------
array (
  'execute' => 'MyTrait::run',
)

Actual result:
--------------
array (
  'execute' => '(null)::run',
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports

 [2012-10-30 15:08 UTC] laruence@php.net

A quick fix is:
iff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index deabcbe..7c51cf6 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -4473,7 +4473,7 @@ ZEND_METHOD(reflection_class, getTraitAliases)
 			zend_trait_method_reference *cur_ref = ce-
>trait_aliases[i]->trait_method;
 
 			if (ce->trait_aliases[i]->alias) {
-				method_name_len = spprintf(&method_name, 0, 
"%s::%s", cur_ref->class_name, cur_ref->method_name);
+				method_name_len = spprintf(&method_name, 0, 
"%s::%s", cur_ref->ce->name, cur_ref->method_name);
 				add_assoc_stringl_ex(return_value, ce-
>trait_aliases[i]->alias, ce->trait_aliases[i]->alias_len + 1, method_n
ame, method_name_len, 0);
 			}
 			i++;

but seems an existsing test take it as a expect output, see: 
https://github.com/php/php-src/blob/master/ext/reflection/tests/traits005.phpt

will verify it later.