JS vs PHP: assignment operator precedence when used with logical-or
问题 (PHP has || and OR . JS only has || .) JS. According to MDN || has higher precedence than = . So this doesn't work: a || a = 1; because it's evaluated as: (a || a) = 1; which results in an "Invalid left-hand side in assignment". I understand that. That makes sense. PHP. According to PHP.net it works the same for PHP: || before = . However, I use this all the time: $a || $a = 1; Why does it work in PHP?? And to top it off: PHP's OR has lower precedence than = , so these shouldn't do the same: