Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Getting static vars


Reply

828 Views

Avatar
UncleCheese

12 December 2008 at 4:00am 4085 Posts

What's the best way to get the value of a static var on an unknown class? Silverstripe uses a pretty clever (albeit ugly) technique that looks something like:

$var = eval("return $className::\$my_var;");

But then in other places i see:

$var = $this->stat('my_var');

And still in other places, I see:

$class = new ReflectionClass('my_class');
$var = $class->getProperty('my_var');

Which is the preferred method? Are a lot of these legacy techniques to support older PHP versions? Seems like it should be the same every time.