Static variable reflection

From: Date: Sat, 09 Oct 2004 06:52:26 +0000
Subject: Static variable reflection
Groups: php.general 
Request: Send a blank email to php-general+get-199055@lists.php.net to get a copy of this message
I have been using and experimenting with PHP 5's reflection API and have ran into a wall. I am trying to access static variables through reflection but it seems as though they cannot be set. The following is some code that reproduces the problem. Thanks to anyone that has insight into my problem. class ReflectionTest { public static $x=5; } $refl = new ReflectionClass('ReflectionTest'); $prop = $refl->getProperty('x'); //$prop->getValue(NULL); not valid! need object $obj = $refl->newInstance(); echo $prop->getValue($obj); $prop->setValue($obj,8);//Won't work! Static variables can't be set! echo $prop->getValue($obj); Output: 5 Fatal error: Uncaught exception 'ReflectionException' with message 'Cannot access non-public member' in C:\Program Files\eclipse\workspace\PHPFlux\test.php:13 Stack trace: #0 {main} thrown in C:\Program Files\eclipse\workspace\PHPFlux\test.php on line 13 Thank you, Ben Dischinger

« previous php.general (#199055) next »