From 607c0fb223a228cfbeac0f5176e1e021b1454206 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Sat, 4 Apr 2009 14:35:28 +0000 Subject: [PATCH] Fix issue reported by Roman Borschel. --- ext/reflection/php_reflection.c | 4 +- .../reflectionProperty_setAccessible.phpt | 57 +++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index c555f0725c..25ec6568d9 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -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); } } /* }}} */ diff --git a/ext/reflection/tests/reflectionProperty_setAccessible.phpt b/ext/reflection/tests/reflectionProperty_setAccessible.phpt index 3e661b0551..4571e463e7 100644 --- a/ext/reflection/tests/reflectionProperty_setAccessible.phpt +++ b/ext/reflection/tests/reflectionProperty_setAccessible.phpt @@ -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" -- 2.40.0