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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

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

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

Getting static vars


Go to End


1758 Views

Avatar
UncleCheese

Forum Moderator, 4102 Posts

12 December 2008 at 4:00am

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.