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

diff --git a/NEWS b/NEWS
index e31a70370349a2a7972a5c64b25e6143d406f9e3..c0b0224761c1483732e9dbeb820e9a82c5398217 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -29,6 +29,8 @@ PHP                                                                        NEWS
   update). (Matteo)
 - Fixed bug #42362 (HTTP status codes 204 and 304 should not be gzipped).
   (Scott, Edward Z. Yang)
+- Fixed an issue with ReflectionProperty::setAccessible().
+  (Sebastian, Roman Borschel)
 
 
 24 Mar 2009, PHP 5.3.0 RC 1
index 75c9fc90a59c1890705f4d02617b405a4eb9da75..3d68dc0c0e4d403dea56d35d2633f1cec8b67903 100644 (file)
@@ -4491,7 +4491,7 @@ ZEND_METHOD(reflection_property, getValue)
                        return;
                }
                zend_unmangle_property_name(ref->prop.name, ref->prop.name_length, &class_name, &prop_name);
-               member_p = zend_read_property(Z_OBJCE_P(object), object, prop_name, strlen(prop_name), 1 TSRMLS_CC);
+               member_p = zend_read_property(ref->ce, object, prop_name, strlen(prop_name), 1 TSRMLS_CC);
                *return_value= *member_p;
                zval_copy_ctor(return_value);
                INIT_PZVAL(return_value);
@@ -4569,7 +4569,7 @@ ZEND_METHOD(reflection_property, setValue)
                        return;
                }
                zend_unmangle_property_name(ref->prop.name, ref->prop.name_length, &class_name, &prop_name);
-               zend_update_property(Z_OBJCE_P(object), object, prop_name, strlen(prop_name), value TSRMLS_CC);
+               zend_update_property(ref->ce, object, prop_name, strlen(prop_name), value TSRMLS_CC);
        }
 }
 /* }}} */
index 927a8a8613e38804575b7368aa93c91c42a2f6cd..cc184c19203bd781382463c3b93d4fb8fdd32c94 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--
 string(44) "Cannot access non-public member A::protected"
@@ -80,3 +128,12 @@ string(1) "e"
 string(1) "f"
 string(1) "g"
 string(1) "h"
+string(44) "Cannot access non-public member B::protected"
+string(50) "Cannot access non-public member B::protectedStatic"
+string(42) "Cannot access non-public member A::private"
+string(1) "a"
+string(1) "f"
+string(1) "c"
+string(1) "e"
+string(1) "f"
+string(1) "g"