Static variable reflection

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux