From: 1000235409 at smail dot shnu dot edu dot cn
Operating system: Windows 7, x86, b7260
PHP version: 5.3.0
PHP Bug Type: Reflection related
Bug description: some private class static fields can be modified by using
reflection
Description:
------------
When calling ReflectionClass::getStaticProperties() with a '&' operator,
we can easily modify the private static fields outside the class, but only
for fields declared in the parent class, not the class itself.
But I don't know if PHP should make it possible to modify the inaccessible
class static fields or not, since the PHP manual just contains a prototype
in Reflection.
Reproduce code:
---------------
class Test {
private static $data = 1;
private static $data4 = 4;
public static function test1() {
echo self::$data;
}
}
class Test2 extends Test {
private static $data2 = 2;
public static $data3 = 3;
}
$r = new ReflectionClass('Test2');
$m = & $r->getStaticProperties(); //here, with the '&'
$m['data'] = 100; //$data is in the parent class.
$m['data4'] = 400; //$data4 is in the parent class.
$m['data2'] = 200; //no effect.
$m['data3'] = 300; //no effect.
Test::test1();
echo "\n";
$m = $r->getStaticProperties();
foreach ($m as $key => $val) {
echo $key . '==>' . $val . "\n";
}
Expected result:
----------------
1
data2==>2
data3==>3
data==>1
data4==>4
/**OR**/
100
data2==>200
data3==>300
data==>100
data4==>400
Actual result:
--------------
100
data2==>2
data3==>3
data==>100
data4==>400
--
Edit bug report at http://bugs.php.net/?id=49074&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=49074&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=49074&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=49074&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=49074&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=49074&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=49074&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=49074&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=49074&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=49074&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=49074&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=49074&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=49074&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=49074&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=49074&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49074&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=49074&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=49074&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=49074&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=49074&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=49074&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=49074&r=mysqlcfg