summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Bergmann <sebastian@php.net>2009-04-04 14:36:23 +0000
committerSebastian Bergmann <sebastian@php.net>2009-04-04 14:36:23 +0000
commit03e48b15358a68a6d8c8526ed11060adae11a809 (patch)
tree5cb236bc4774d098c90768dcbe83c6002b76df86
parent99152e8f58a1e33735498323bdf8c5984120e16a (diff)
downloadphp-git-03e48b15358a68a6d8c8526ed11060adae11a809.tar.gz
MFH: Fix issue reported by Roman Borschel.
-rw-r--r--NEWS2
-rw-r--r--ext/reflection/php_reflection.c4
-rw-r--r--ext/reflection/tests/reflectionProperty_setAccessible.phpt57
3 files changed, 61 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index e31a703703..c0b0224761 100644
--- 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
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index 75c9fc90a5..3d68dc0c0e 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -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);
}
}
/* }}} */
diff --git a/ext/reflection/tests/reflectionProperty_setAccessible.phpt b/ext/reflection/tests/reflectionProperty_setAccessible.phpt
index 927a8a8613..cc184c1920 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--
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"