]> granicus.if.org Git - php/commitdiff
fix #39001 (ReflectionProperty returns incorrect declaring class for protected proper...
authorAntony Dovgal <tony2001@php.net>
Mon, 2 Oct 2006 12:15:47 +0000 (12:15 +0000)
committerAntony Dovgal <tony2001@php.net>
Mon, 2 Oct 2006 12:15:47 +0000 (12:15 +0000)
ext/reflection/php_reflection.c
ext/reflection/tests/bug39001.phpt [new file with mode: 0644]

index 43113587c44717cd3751446f73ceacd60cfe3c66..6519f433d1aa5819be78cd32cbffd90bb4bfbbb2 100644 (file)
@@ -4080,12 +4080,19 @@ ZEND_METHOD(reflection_property, getDeclaringClass)
        property_reference *ref;
        zend_class_entry *tmp_ce, *ce;
        zend_property_info *tmp_info;
+       zstr prop_name, class_name;
+       int prop_name_len;
 
        METHOD_NOTSTATIC_NUMPARAMS(reflection_property_ptr, 0);
        GET_REFLECTION_OBJECT_PTR(ref);
 
+       if (zend_u_unmangle_property_name(UG(unicode)?IS_UNICODE:IS_STRING, ref->prop->name, ref->prop->name_length, &class_name, &prop_name) != SUCCESS) {
+               RETURN_FALSE;
+       }
+
+       prop_name_len = USTR_LEN(prop_name);
        ce = tmp_ce = ref->ce;
-       while (tmp_ce && zend_u_hash_find(&tmp_ce->properties_info, UG(unicode)?IS_UNICODE:IS_STRING, ref->prop->name, ref->prop->name_length + 1, (void **) &tmp_info) == SUCCESS) {
+       while (tmp_ce && zend_u_hash_find(&tmp_ce->properties_info, UG(unicode)?IS_UNICODE:IS_STRING, prop_name, prop_name_len + 1, (void **) &tmp_info) == SUCCESS) {
                ce = tmp_ce;
                tmp_ce = tmp_ce->parent;
        }
diff --git a/ext/reflection/tests/bug39001.phpt b/ext/reflection/tests/bug39001.phpt
new file mode 100644 (file)
index 0000000..bf8927d
--- /dev/null
@@ -0,0 +1,31 @@
+--TEST--
+Bug #39001 (ReflectionProperty returns incorrect declaring class for protected properties)
+--FILE--
+<?php
+
+class Meta {
+}
+
+class CParent extends Meta {
+       public $publicVar;
+       protected $protectedVar;
+}
+
+class Child extends CParent {
+}
+
+$r = new ReflectionClass('Child');
+
+var_dump($r->getProperty('publicVar')->getDeclaringClass()->getName());
+var_dump($r->getProperty('protectedVar')->getDeclaringClass()->getName());
+
+echo "Done\n";
+?>
+--EXPECTF--    
+string(7) "CParent"
+string(7) "CParent"
+Done
+--UEXPECTF--
+unicode(7) "CParent"
+unicode(7) "CParent"
+Done