Jump to:

17452 Posts in 4473 Topics by 1971 members


SilverStripe Forums » Archive » Getting static vars

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

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

Page: 1
Go to End
Author Topic: 816 Views
  • UncleCheese
    4085 Posts

    Getting static vars Link to this post

    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.

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.