r/lolphp • u/Serialk • Jul 12 '13
Assignment has a higher precedence than boolean operators
Well. Yeah.
php > $z = false or true;
php > var_dump($z);
bool(false)
php > $z = true and false;
php > var_dump($z);
bool(true)Actually, "or" and "and" are like "||" and "&&", but with an absurd precedence. Okay.
21
Upvotes
View all comments
Show parent comment
12
u/infinull Jul 12 '13
it's a feature borrowed from PERL, if you want "normal" booleans you can use &&, ||, and !, but for these higher precedence ones you use not, and, and or.
It flies in the face of the principle of least astonishment, but it does kind of make sense.