|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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',
)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 08:00:01 2025 UTC |
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.