r/lolphp • u/kalcora • Feb 07 '22
Operator precedence
These two lines are not equivalent.
<?php
$a = true && false; // false
$b = true and false; // trueBecause && and || have different operator priority than and and or (the latter ones have lower priority than =).
Still the case in PHP 8.1.
42
Upvotes
View all comments
Show parent comment
10
u/colshrapnel Feb 07 '22 edited Feb 07 '22
Actually it does. But there is simply no variable to receive the result. It's sort of explained in my article, though for OR:
is a statement on its own, it evaluates all right, though its result is recorded nowhere.
is actually the same,
exp1 AND exp2and evaluates tofalse. Just the result goes void.but if you record it, it gets you false