php - Operators precedence of "or" and assignment -
found interesting code snippet today. simplified, looks this:
$var = null; $var or $var = '123'; $var or $var = '312'; var_dump($var); the thing that, know, precedence of assignment higher or, so, assume, var_dump should output 312 (first - assign, second - compare logically). result defferent, getting 123 (first - check if $var converting true, second - if not, assign value).
the questions how work?
why behavior same or , ||?
you can see examples behaviour in logical operators
also can read artical short-circuit evaluation
the short-circuit expression
x sand y(using sand denote short-circuit variety) equivalent conditional expressionif x y else false;expressionx sor yequivalentif x true else y.
in php.
return x() , y(); equal to
if (x()) return (bool)y(); else return false; return x() or y(); equal to
if (x()) return true; else return (bool)y(); so, deal not in precedence.
Comments
Post a Comment