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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Does Object::set_static() actually work??


5 Posts   828 Views


1 October 2009 at 11:56pm Community Member, 509 Posts

Hi all,

I have tried on several occasions now to use Object::set_static() to change the Static variable of an object, but it never seems to do anything.

The best example I can give is while I am trying to change the $url_segment in CMSMain. I use this:

Object::set_static('CMSMain', 'url_segment', 'cms');

But it seems to make no difference, if I manually change the variable however, it does what I want to.

Anyone know whats going on? I do the call in my _config.php file??




2 October 2009 at 12:45am Community Member, 901 Posts

Any particular reason why you want to use Object::set_static instead of simply CMSMain::$url_segment = <value>. What's the advantage of the Object::set_static approach?


2 October 2009 at 1:37am Community Member, 509 Posts

I have done that, I was just thinking Object::set_static() must be preferred to just directly setting the variable, otherwise I wasn't sure why it would exist...

Maybe I am thinking too much :)


2 October 2009 at 1:41am Community Member, 901 Posts

I think the set_static method helps in cases where decorator or "extensions" are being used. So that you can set a static variable that doesn't really belong to the object itself, but to an extension of that object. I'm not really sure though ;)

But there's nothing wrong with setting the static variable directly. It surely is the better option from a performance point of view.


2 October 2009 at 1:57am Community Member, 509 Posts

Ok cool, well it seems to be working ok, so I will stick with the direct alteration :).