Edit report at https://bugs.php.net/bug.php?id=63399&edit=1

 ID:                 63399
 Comment by:         r dot wilczek at web-appz dot de
 Reported by:        r dot wilczek at web-appz dot de
 Summary:            ReflectionClass::getTraitAliases() incorrectly
                     resolves traitnames
 Status:             Analyzed
 Type:               Bug
 Package:            Reflection related
 Operating System:   Linux x86_64
 PHP Version:        5.4.7RC1
 Assigned To:        laruence
 Block user comment: N
 Private report:     N

 New Comment:

I think, that 
https://github.com/php/php-src/blob/master/ext/reflection/tests/traits005.phpt 
just shows the actual implementation and does not define expected behaviour.

... who would seriously expect '(null)'?


Previous Comments:
------------------------------------------------------------------------
[2012-10-30 15:08:40] larue...@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.

------------------------------------------------------------------------
[2012-10-30 14:19:43] 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',
)


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=63399&edit=1

Reply via email to