diff options
-rw-r--r-- | ext/reflection/php_reflection.c | 2 | ||||
-rw-r--r-- | ext/reflection/tests/bug63399.phpt | 49 | ||||
-rw-r--r-- | ext/reflection/tests/traits005.phpt | 6 |
3 files changed, 53 insertions, 4 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index deabcbe7a4..7c51cf6cca 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_name, method_name_len, 0); } i++; diff --git a/ext/reflection/tests/bug63399.phpt b/ext/reflection/tests/bug63399.phpt new file mode 100644 index 0000000000..393b861690 --- /dev/null +++ b/ext/reflection/tests/bug63399.phpt @@ -0,0 +1,49 @@ +--TEST-- +Bug #63399 (ReflectionClass::getTraitAliases() incorrectly resolves traitnames) +--FILE-- +<?php +trait Trait1 { + public function run() {} + public function say() {} +} + +trait Trait2 { + public function run() {} + public function say() {} +} + +class MyClass +{ + use Trait1, Trait2 { + Trait1::run as execute; + Trait1::say insteadof Trait2; + Trait2::run insteadof Trait1; + Trait2::say as talk; + } +} + +$ref = new ReflectionClass('MyClass'); + +print_r($ref->getTraitAliases()); +print_r($ref->getTraits()); + +?> +--EXPECT-- +Array +( + [execute] => Trait1::run + [talk] => Trait2::say +) +Array +( + [Trait1] => ReflectionClass Object + ( + [name] => Trait1 + ) + + [Trait2] => ReflectionClass Object + ( + [name] => Trait2 + ) + +) diff --git a/ext/reflection/tests/traits005.phpt b/ext/reflection/tests/traits005.phpt index 1496a35ec9..4cfa6c04f0 100644 --- a/ext/reflection/tests/traits005.phpt +++ b/ext/reflection/tests/traits005.phpt @@ -28,14 +28,14 @@ array(0) { class C3: array(1) { ["a1"]=> - string(10) "(null)::m1" + string(6) "T1::m1" } class C4: array(2) { ["a1"]=> - string(10) "(null)::m1" + string(6) "T1::m1" ["a2"]=> - string(10) "(null)::m2" + string(6) "T1::m2" } |