where:
$b = true;
$c = 0;
$a = ($a ? ($a ? $b : $c) : ($c ? $a : $b));
I'm not sure how to work out a.
So I understand that this is a shorthand operator, and usually it's a case of:
$value ? true : false
meaning
if $a = true { true } else { false };
so:
if $a{
if $a{
true;}
else{
0;};
else{
if $0{
$a;}
else{
true;}
};
does this make the value of $a true?
The value of
$awould betrueThe shorthand can be interpreted like this:
Because
$ais false for not existing in the first place, it immediately jumps to the else statement in that. So the only part that matters to you is:0is the same asfalse, so$cwill come back as false, therefore$ais equal to$b, which istrue.Edit:
There is some discussion on the notice that is thrown, but this fails to account for the fact that notices are not truly errors and because of this there is no interruption to the code. The result is not
Notice: Undefined variable: a, the "result" (think these people mean output) would be blank if it weren't for us determining the value of$aat the end withvar_dump. The question was as to what the value of$abecomes, not what appears on your screen.Something displaying on your screen in re to a variable not being set has nothing to do with the value of what
$ais.If you execute the following code, the notice is not the only thing realized:
So the output is:
The fact that a notice was thrown does not prevent
$afrom becoming true.Also notices are easily suppressed...
would result in
$astill becoming true, and without seeing the notice.