Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Omitting the second part of the ternary operator

Given the following expression:

$att['menutext'] = isset($attrib_in['i_menu_text']) ? : $this->getID();

If it evaluates to true, will $att['menutext'] be set to true or $this->getID()?

like image 895
Sinthia V Avatar asked Nov 11 '11 20:11

Sinthia V


1 Answers

Yes, in version 5.3+ the middle expression is optional and returns true.

$a = (true ? : 1); // $a evaluates to true.
$a = (false ? : 1); // $a evaluates to 1.
like image 141
Jim H. Avatar answered Oct 13 '22 00:10

Jim H.