]> granicus.if.org Git - php/commitdiff
Fixed bug #63399 (ReflectionClass::getTraitAliases() incorrectly resolves traitnames)
authorXinchen Hui <laruence@php.net>
Wed, 31 Oct 2012 03:13:32 +0000 (11:13 +0800)
committerXinchen Hui <laruence@php.net>
Wed, 31 Oct 2012 03:13:32 +0000 (11:13 +0800)
NEWS
ext/reflection/php_reflection.c
ext/reflection/tests/bug63399.phpt [new file with mode: 0644]
ext/reflection/tests/traits005.phpt

diff --git a/NEWS b/NEWS
index 74dab3cbfbf1eeaa5f778f97d9b1a7ba5188f001..7a1438a819783ac6462af7f94f34b5f4a0aebe2e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -33,6 +33,10 @@ PHP                                                                        NEWS
   . Fixed bug #63297 (Phar fails to write an openssl based signature).
     (Anatoliy)
 
+- Reflection:
+  . Fixed bug #63399 (ReflectionClass::getTraitAliases() incorrectly resolves
+    traitnames). (Laruence)
+
 18 Oct 2012, PHP 5.4.8
 
 - CLI server:
index 7c9981924ded1ad2023fb1d5c3d1a8f290632f5c..53b2389d638795fa66862d453ff1abfd89e0aa13 100644 (file)
@@ -4465,7 +4465,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 (file)
index 0000000..393b861
--- /dev/null
@@ -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
+        )
+
+)
index 1496a35ec99ad00f2a95318db92d74949a2f583a..4cfa6c04f03a852b668fff00cbc4559a032ad71a 100644 (file)
@@ -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"
 }