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.
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
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.
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.
I think it's called a ternary operator or conditional operator...
Read more about it here (scroll down a bit):
http://www.php.net/manual/en/language.operators.comparison.php
or in this blog post:
http://davidwalsh.name/javascript-shorthand-if-else-examples
Cheers
The :: allows you to use the function of the DataObject class without instantiating an actual object from it.
Thanks guys, tat explain very well!