Let's say we got a simple code like this:
// $foo and $bar aren't defined before
$foo = 5 && $bar = 15;
// var_dump()
// $foo is (bool) TRUE
// $bar is (int) 15
so I assume it works like:
$foo = (5 && ($bar = 15))
but in my opinion it should be:
$foo = ((5 && $bar) = 15) // should throw syntax error due FALSE = 15
- evaluation form left to right [$foo want 5 but && is higher]
- && got the highest priority [so && takes 5 and $bar]
- 5 == TRUE; $bar == Undefined [so it's NULL == FALSE]
- = got the right associativity [waits for evaluation of (5 && $bar)]
Please explain it in easiest way (on some other examples) to poor man like me. Regards.