Reputation: 2746
When I evaluate the expressions below, the result is completely different depending on the evaluation order and whether I assign the value or not:
$a = true;
$b = false;
var_dump($a and $b); // false
$c = $a and $b;
var_dump($c); // true
$d = $b and $a;
var_dump($d); // false
I'm completely stumped. Why does this happen?
Upvotes: 1
Views: 215
Reputation: 37382
=
has higher priority than and
. So $c = $a and $b;
is the same as ($c = $a) and $b;
, value of $a is assigned to $c. This is different from &&
which has higher priority than =
, so $c = $a && $b
evaluates to $c = ($a && $b)
;
Upvotes: 6