#46718 [NEW]: ReflectionProperty::setValue() and ReflectionProperty::setAccessible()
| From: | sebastian@php.net | Date: | Sat, 29 Nov 2008 14:48:42 +0000 |
| Subject: | #46718 [NEW]: ReflectionProperty::setValue() and ReflectionProperty::setAccessible() | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-131487@lists.php.net to get a copy of this message | ||
From: sebastian@php.net
Operating system: irrelevant
PHP version: 5.3CVS-2008-11-29 (CVS)
PHP Bug Type: Reflection related
Bug description: ReflectionProperty::setValue() and ReflectionProperty::setAccessible()
Description:
------------
ReflectionProperty::setValue() ignores the setting made with
ReflectionProperty::setAccessible(TRUE).
Reproduce code:
---------------
<?php
class A {
protected $protected = 'a';
protected static $protectedStatic = 'b';
private $private = 'c';
private static $privateStatic = 'd';
}
$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));
}
catch (ReflectionException $e) {
var_dump($e->getMessage());
}
try {
var_dump($protectedStatic->getValue());
}
catch (ReflectionException $e) {
var_dump($e->getMessage());
}
try {
var_dump($private->getValue($a));
}
catch (ReflectionException $e) {
var_dump($e->getMessage());
}
try {
var_dump($privateStatic->getValue());
}
catch (ReflectionException $e) {
var_dump($e->getMessage());
}
$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());
?>
Expected result:
----------------
string(44) "Cannot access non-public member A::protected"
string(50) "Cannot access non-public member A::protectedStatic"
string(42) "Cannot access non-public member A::private"
string(48) "Cannot access non-public member A::privateStatic"
string(1) "a"
string(1) "b"
string(1) "c"
string(1) "d"
string(1) "e"
string(1) "f"
string(1) "g"
string(1) "h"
Actual result:
--------------
string(44) "Cannot access non-public member A::protected"
string(50) "Cannot access non-public member A::protectedStatic"
string(42) "Cannot access non-public member A::private"
string(48) "Cannot access non-public member A::privateStatic"
string(1) "a"
string(1) "b"
string(1) "c"
string(1) "d"
ReflectionException: Cannot access non-public member A::protected in
/usr/local/src/php/php-5.3/reflectionProperty_setAccessible.php on line 57
Call Stack:
0.0010 355044 1. {main}()
/usr/local/src/php/php-5.3/reflectionProperty_setAccessible.php:0
0.0294 365972 2. ReflectionProperty->setValue()
/usr/local/src/php/php-5.3/reflectionProperty_setAccessible.php:57
--
Edit bug report at http://bugs.php.net/?id=46718&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=46718&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=46718&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=46718&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=46718&r=fixedcvs
Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=46718&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=46718&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=46718&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=46718&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=46718&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=46718&r=support
Expected behavior: http://bugs.php.net/fix.php?id=46718&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=46718&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=46718&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=46718&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46718&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=46718&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=46718&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=46718&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=46718&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=46718&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=46718&r=mysqlcfg