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

Simple Question on Php


Reply


4 Posts   729 Views

Avatar
tfliam

Community Member, 20 Posts

13 October 2011 at 8:55pm

Hi, I am doing a tutorial 2, for the code below:

return ($news) ? DataObject::get("ArticlePage", "ParentID = $news->ID", "Date DESC", "", $num) : false;

What do the symbol '?' and ':' means? Thanks.

Avatar
Invader_Zim

Community Member, 141 Posts

13 October 2011 at 9:31pm

I think it's called a ternary operator or conditional operator...

Read more about it here (scroll down a bit):
[url]http://www.php.net/manual/en/language.operators.comparison.php[/url]

or in this blog post:
[url]http://davidwalsh.name/javascript-shorthand-if-else-examples[/url]

Cheers

Avatar
dendeffe

Community Member, 135 Posts

13 October 2011 at 11:30pm

The :: allows you to use the function of the DataObject class without instantiating an actual object from it.

Avatar
tfliam

Community Member, 20 Posts

14 October 2011 at 3:01pm

Thanks guys, tat explain very well!