On Sat, 2004-10-30 at 14:45, Hodicska Gergely wrote: > Hi! > > I tried to get answer on the general list, but I didn't get. > I have a little example, which generate strange output. > > $a = 0; > $b = 1; > if ($a = 1 && $b = 0) { > echo 'true '; > var_dump($a); > var_dump($b); > } else { > echo 'false '; > var_dump($a); > var_dump($b); > } > Runing this we get: "flase bool(false) int(0)" > > After the precedence table the first step should be evaluating the &&, > and we get something like this: $a = false = 0, which should generate an > error, while there isn't an "lvalue" on the left side of the =. > But doesn't this happen. It seems, that the evaluation of the first = > came before evaluating the &&. > > Can someone exactly explain how PHP process this condition?
You are mixing right and left associativity operators without parenthesis. The PHP doc at: http://www.php.net/manual/en/language.operators.php Clearly states that you can do !$a = foo() where the result of foo() will be assigned to $a. Thus in your example the order of evaluation is: evaluate $b = 0 evaluate the result of 1 && $b assign the previous evaluation result to $a Thus: $b = 0 1 && 0 = false $a = false HTH, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------' -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php