Re: A serious bug? "or" operator gives out diffferent results depending on order of operands
| From: | Rasmus Lerdorf | Date: | Thu, 23 Dec 2004 20:21:32 +0000 |
| Subject: | Re: A serious bug? "or" operator gives out diffferent results depending on order of operands | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-205098@lists.php.net to get a copy of this message | ||
Bogdan Ribic wrote:
Here's a little test script: -------------------- $x = 2; $y = 10; $b1 = is_null($x) or ($y > 5); $b2 = ($y > 5) or is_null($x); var_dump($b1); var_dump($b2); -------------------- Obviously, it should be false for both $b1 and $b2, but the output is: bool(false) bool(true) Is this a bug? I tried dumping values of two expressions, they are both boolean and correct value. Tried assigning values to two temp vars and then or-ing these two, and that gave correct results. I really cannot see what am I doing wrong. Tried this with php 4.3.2 and 4.3.9, and I get these weird results both times. Maybe I should herd cattle or something :)The whole point of OR is that it is a very low precedence operator. Think of it as being at the bottom of the precedence table (it isn't quite, ',' is lower) so you can do:
$a = b() + $c / $d OR echo "false";That is, do everything before the OR first, then see what that evaluates to before applying the OR. This wouldn't work if it took precedence over anything in the rest of the expression. -Rasmus