sebastian Sat Nov 29 15:58:30 2008 UTC
Modified files:
/php-src/ext/reflection php_reflection.c
/php-src/ext/reflection/tests reflectionProperty_setAccessible.phpt
Log:
Fix #46718: ReflectionProperty::setValue() and
ReflectionProperty::setAccessible().
http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/php_reflection.c?r1=1.327&r2=1.328&diff_format=u
Index: php-src/ext/reflection/php_reflection.c
diff -u php-src/ext/reflection/php_reflection.c:1.327
php-src/ext/reflection/php_reflection.c:1.328
--- php-src/ext/reflection/php_reflection.c:1.327 Thu Nov 27 19:02:45 2008
+++ php-src/ext/reflection/php_reflection.c Sat Nov 29 15:58:29 2008
@@ -20,7 +20,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_reflection.c,v 1.327 2008/11/27 19:02:45 dmitry Exp $ */
+/* $Id: php_reflection.c,v 1.328 2008/11/29 15:58:29 sebastian Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -4537,7 +4537,7 @@
METHOD_NOTSTATIC(reflection_property_ptr);
GET_REFLECTION_OBJECT_PTR(ref);
- if (!(ref->prop.flags & ZEND_ACC_PUBLIC)) {
+ if (!(ref->prop.flags & ZEND_ACC_PUBLIC) && ref->ignore_visibility ==
0) {
_default_get_entry(getThis(), "name", sizeof("name"), &name
TSRMLS_CC);
zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
"Cannot access non-public member %v::%v",
intern->ce->name, Z_UNIVAL(name));
@@ -4581,10 +4581,15 @@
zend_u_hash_quick_update(prop_table, utype,
ref->prop.name, ref->prop.name_length+1, ref->prop.h, &value, sizeof(zval *),
(void **) &foo);
}
} else {
+ zstr class_name, prop_name;
+ int prop_name_len;
+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "oz",
&object, &value) == FAILURE) {
return;
}
- zend_u_update_property(Z_OBJCE_P(object), object,
UG(unicode)?IS_UNICODE:IS_STRING, ref->prop.name, ref->prop.name_length, value
TSRMLS_CC);
+ zend_u_unmangle_property_name(UG(unicode)?IS_UNICODE:IS_STRING,
ref->prop.name, ref->prop.name_length, &class_name, &prop_name);
+ prop_name_len = UG(unicode) ? u_strlen(prop_name.u) :
strlen(prop_name.s);
+ zend_u_update_property(Z_OBJCE_P(object), object,
UG(unicode)?IS_UNICODE:IS_STRING, prop_name, prop_name_len, value TSRMLS_CC);
}
}
/* }}} */
@@ -5433,7 +5438,7 @@
php_info_print_table_start();
php_info_print_table_header(2, "Reflection", "enabled");
- php_info_print_table_row(2, "Version", "$Id: php_reflection.c,v 1.327
2008/11/27 19:02:45 dmitry Exp $");
+ php_info_print_table_row(2, "Version", "$Id: php_reflection.c,v 1.328
2008/11/29 15:58:29 sebastian Exp $");
php_info_print_table_end();
} /* }}} */
http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/tests/reflectionProperty_setAccessible.phpt?r1=1.2&r2=1.3&diff_format=u
Index: php-src/ext/reflection/tests/reflectionProperty_setAccessible.phpt
diff -u php-src/ext/reflection/tests/reflectionProperty_setAccessible.phpt:1.2
php-src/ext/reflection/tests/reflectionProperty_setAccessible.phpt:1.3
--- php-src/ext/reflection/tests/reflectionProperty_setAccessible.phpt:1.2
Sat May 24 13:35:03 2008
+++ php-src/ext/reflection/tests/reflectionProperty_setAccessible.phpt Sat Nov
29 15:58:30 2008
@@ -2,43 +2,81 @@
Test ReflectionProperty::setAccessible().
--FILE--
<?php
-
-class TestClass {
- public $pub;
- public $pub2 = 5;
- static public $stat = "static property";
- protected $prot = 4;
- private $priv = "keepOut";
+class A {
+ protected $protected = 'a';
+ protected static $protectedStatic = 'b';
+ private $private = 'c';
+ private static $privateStatic = 'd';
}
-class AnotherClass {
+$a = new A;
+$protected = new ReflectionProperty($a, 'protected');
+$protectedStatic = new ReflectionProperty('A', 'protectedStatic');
+$private = new ReflectionProperty($a, 'private');
+$privateStatic = new ReflectionProperty('A', 'privateStatic');
+
+try {
+ var_dump($protected->getValue($a));
}
-$instance = new TestClass();
+catch (ReflectionException $e) {
+ var_dump($e->getMessage());
+}
-echo "\nProtected property:\n";
-$propInfo = new ReflectionProperty('TestClass', 'prot');
try {
- var_dump($propInfo->getValue($instance));
+ var_dump($protectedStatic->getValue());
}
-catch(Exception $exc) {
- echo $exc->getMessage(), "\n";
+
+catch (ReflectionException $e) {
+ var_dump($e->getMessage());
}
-$propInfo->setAccessible(true);
-var_dump($propInfo->getValue($instance));
+try {
+ var_dump($private->getValue($a));
+}
+
+catch (ReflectionException $e) {
+ var_dump($e->getMessage());
+}
-$propInfo->setAccessible(false);
try {
- var_dump($propInfo->getValue($instance));
+ var_dump($privateStatic->getValue());
}
-catch(Exception $exc) {
- echo $exc->getMessage(), "\n";
+
+catch (ReflectionException $e) {
+ var_dump($e->getMessage());
}
-?>
---EXPECTF--
-Protected property:
-Cannot access non-public member TestClass::prot
-int(4)
-Cannot access non-public member TestClass::prot
+$protected->setAccessible(TRUE);
+$protectedStatic->setAccessible(TRUE);
+$private->setAccessible(TRUE);
+$privateStatic->setAccessible(TRUE);
+
+var_dump($protected->getValue($a));
+var_dump($protectedStatic->getValue());
+var_dump($private->getValue($a));
+var_dump($privateStatic->getValue());
+
+$protected->setValue($a, 'e');
+$protectedStatic->setValue('f');
+$private->setValue($a, 'g');
+$privateStatic->setValue('h');
+
+var_dump($protected->getValue($a));
+var_dump($protectedStatic->getValue());
+var_dump($private->getValue($a));
+var_dump($privateStatic->getValue());
+?>
+--EXPECT--
+unicode(44) "Cannot access non-public member A::protected"
+unicode(50) "Cannot access non-public member A::protectedStatic"
+unicode(42) "Cannot access non-public member A::private"
+unicode(48) "Cannot access non-public member A::privateStatic"
+unicode(1) "a"
+unicode(1) "b"
+unicode(1) "c"
+unicode(1) "d"
+unicode(1) "e"
+unicode(1) "f"
+unicode(1) "g"
+unicode(1) "h"
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php