I need to assign one of two variables to a third variable, using the value of the second variable if the first (bool) is false or undefined.
I usually do this using triple notation:
$foobar = ($some_prefix_and_some_variable_name) ? $some_prefix_and_some_variable_name : $bar ;
but sometimes it’s not so beautiful if the variable name $ foo is very long, since it should be repeated in this notation.
Now my question is: it’s just as good to use these notation:
$foobar = $some_prefix_and_some_variable_name OR $foobar = $bar;
and is this designation interchangeable with the triple version?
Because it $foobar = $foo OR $foobar = $bar;evaluates this:
$foobar = $foo OR $foobar = $bar;
Assign foo foobar.* Is there any value there? * If not, assign bar foobar.
While another estimates:
foo?* foobar = foo* else foobar = bar
if! foo , foo . . , .
- . 5.3 , , , .
, , , , , , WTF?
PHP 5.3 :
$foobar = $fooooooooooooooooooooooooo ?: $bar ;
$foobar = $fooooooooooooooooooooooooo ?: $bar;
:
PHP 5.3 . expr1 ?: expr3 expr1, expr1 TRUE expr3 .
expr1 ?: expr3
expr1
TRUE
expr3
, :
$foobar = $fooooooooooooooooooooooooo OR $foobar = $bar;
. , , , ! , , , ( ), , , . , , , - , ( !).
, , :
if($fooooooooooooooooooooooooo){ $foobar =$fooooooooooooooooooooooooo; } else { $foobar = $bar; }
, , , .