]> granicus.if.org Git - php/commitdiff
Fix issue reported by Roman Borschel.
authorSebastian Bergmann <sebastian@php.net>
Sat, 4 Apr 2009 14:35:28 +0000 (14:35 +0000)
committerSebastian Bergmann <sebastian@php.net>
Sat, 4 Apr 2009 14:35:28 +0000 (14:35 +0000)
ext/reflection/php_reflection.c
ext/reflection/tests/reflectionProperty_setAccessible.phpt

index c555f0725cb3efa940c3e3f7daff2fddb28d757a..25ec6568d9f7c47ce30ccd6d6df20ee88b049e57 100644 (file)
@@ -4726,7 +4726,7 @@ ZEND_METHOD(reflection_property, getValue)
                }
                zend_u_unmangle_property_name(IS_UNICODE, ref->prop.name, ref->prop.name_length, &class_name, &prop_name);
                prop_name_len = u_strlen(prop_name.u);
-               member_p = zend_u_read_property(Z_OBJCE_P(object), object, IS_UNICODE, prop_name, prop_name_len, 1 TSRMLS_CC);
+               member_p = zend_u_read_property(ref->ce, object, IS_UNICODE, prop_name, prop_name_len, 1 TSRMLS_CC);
                *return_value= *member_p;
                zval_copy_ctor(return_value);
                INIT_PZVAL(return_value);
@@ -4807,7 +4807,7 @@ ZEND_METHOD(reflection_property, setValue)
                }
                zend_u_unmangle_property_name(IS_UNICODE, ref->prop.name, ref->prop.name_length, &class_name, &prop_name);
                prop_name_len = u_strlen(prop_name.u);
-               zend_u_update_property(Z_OBJCE_P(object), object, IS_UNICODE, prop_name, prop_name_len, value TSRMLS_CC);
+               zend_u_update_property(ref->ce, object, IS_UNICODE, prop_name, prop_name_len, value TSRMLS_CC);
        }
 }
 /* }}} */
index 3e661b055121f6e3fb7470602058e78af1c4bc33..4571e463e70250cb3e7c03d6c1d6eae6fabfe3c2 100644 (file)
@@ -9,6 +9,8 @@ class A {
     private static $privateStatic = 'd';
 }
 
+class B extends A {}
+
 $a               = new A;
 $protected       = new ReflectionProperty($a, 'protected');
 $protectedStatic = new ReflectionProperty('A', 'protectedStatic');
@@ -66,6 +68,52 @@ var_dump($protected->getValue($a));
 var_dump($protectedStatic->getValue());
 var_dump($private->getValue($a));
 var_dump($privateStatic->getValue());
+
+$a               = new A;
+$b               = new B;
+$protected       = new ReflectionProperty($b, 'protected');
+$protectedStatic = new ReflectionProperty('B', 'protectedStatic');
+$private         = new ReflectionProperty($a, 'private');
+
+try {
+    var_dump($protected->getValue($b));
+}
+
+catch (ReflectionException $e) {
+    var_dump($e->getMessage());
+}
+
+try {
+    var_dump($protectedStatic->getValue());
+}
+
+catch (ReflectionException $e) {
+    var_dump($e->getMessage());
+}
+
+try {
+    var_dump($private->getValue($b));
+}
+
+catch (ReflectionException $e) {
+    var_dump($e->getMessage());
+}
+
+$protected->setAccessible(TRUE);
+$protectedStatic->setAccessible(TRUE);
+$private->setAccessible(TRUE);
+
+var_dump($protected->getValue($b));
+var_dump($protectedStatic->getValue());
+var_dump($private->getValue($b));
+
+$protected->setValue($b, 'e');
+$protectedStatic->setValue('f');
+$private->setValue($b, 'g');
+
+var_dump($protected->getValue($b));
+var_dump($protectedStatic->getValue());
+var_dump($private->getValue($b));
 ?>
 --EXPECT--
 unicode(44) "Cannot access non-public member A::protected"
@@ -80,3 +128,12 @@ unicode(1) "e"
 unicode(1) "f"
 unicode(1) "g"
 unicode(1) "h"
+unicode(44) "Cannot access non-public member B::protected"
+unicode(50) "Cannot access non-public member B::protectedStatic"
+unicode(42) "Cannot access non-public member A::private"
+unicode(1) "a"
+unicode(1) "f"
+unicode(1) "c"
+unicode(1) "e"
+unicode(1) "f"
+unicode(1) "g"