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.

General Questions /

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

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

Does Object::set_static() actually work??


Go to End


5 Posts   1209 Views

Avatar
Mo

Community Member, 541 Posts

1 October 2009 at 11:56pm

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??

Cheers,

Mo

Avatar
bummzack

Community Member, 904 Posts

2 October 2009 at 12:45am

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?

Avatar
Mo

Community Member, 541 Posts

2 October 2009 at 1:37am

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 :)

Avatar
bummzack

Community Member, 904 Posts

2 October 2009 at 1:41am

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.

Avatar
Mo

Community Member, 541 Posts

2 October 2009 at 1:57am

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