Re: Static variable reflection

From: Date: Mon, 11 Oct 2004 08:05:23 +0000
Subject: Re: Static variable reflection
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-13255@lists.php.net to get a copy of this message
Hello Benjamin, Monday, October 11, 2004, 1:36:25 AM, you wrote: > I sent this message to the php-general list and didn't get any > replies. This seems to be a potential bug so I thought it would be > appropriate to the php-dev list. Thank you for reading 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 fixed in cvs -> please try the the newest version before reporting bugs and always check the bug database for related bugs first. > $obj = $refl->newInstance(); > echo $prop->getValue($obj); > $prop->setValue($obj,8);//Won't work! Static variables can't be set! why shouldn't you be able to set static properties? the point is you cannot set consts > 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 -- Best regards, Marcus mailto:helly@php.net

« previous php.internals (#13255) next »