Re: [PHP] runtime access to static variable
Jack Bates-2 wrote: How do I access a static variable when I do not know the name of the class until runtime? Why not just: eval('$staticVal = '.get_class($myClass).'::staticVarName;'); ...now the value is in $staticVal. Or am I missing something here? No need to tell me eval is evil ;) -- View this message in context: http://www.nabble.com/runtime-access-to-static-variable-tp21041719p24433169.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] runtime access to static variable
On Fri, Jul 10, 2009 at 4:25 PM, Madbreaksnab...@vektral.com wrote: Jack Bates-2 wrote: How do I access a static variable when I do not know the name of the class until runtime? Why not just: eval('$staticVal = '.get_class($myClass).'::staticVarName;'); ...now the value is in $staticVal. Or am I missing something here? No need to tell me eval is evil ;) -- View this message in context: http://www.nabble.com/runtime-access-to-static-variable-tp21041719p24433169.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php if you need to access to a class constant use the built-in function if( defined( get_class($myClass) .'::THE_CONST' ) ) constant( get_class($myClass) .'::THE_CONST' ); They are very helpful -- Martin Scotta -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] runtime access to static variable
Try this, maybe: ($className)::$STEPS -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] runtime access to static variable
Jack Bates wrote: How do I access a static variable when I do not know the name of the class until runtime? I have the following example PHP: ket% cat test.php ?php class Test { public static $STEPS = array( 'foo', 'bar'); } $className = 'Test'; var_dump($className::$STEPS); ket% Unfortunately when I run it I get: ket% php test.php Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM in /home/jablko/trash/test.php on line 13 ket% I can call a static function using call_user_func(array($className, 'functionName')), and I can access a class constant using constant($className.'::CONSTANT_NAME'). How do I access a static variable? Check this out: http://us2.php.net/manual/en/language.oop5.static.php It actually won't work until 5.3.0 when they add late static binding. Thank you, Micah Gersten onShore Networks Internal Developer http://www.onshore.com Thank you, Micah Gersten onShore Networks Internal Developer http://www.onshore.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php