Re: A serious bug? "or" operator gives out diffferent results depending
| From: | John Holmes | Date: | Thu, 23 Dec 2004 19:44:22 +0000 |
| Subject: | Re: A serious bug? "or" operator gives out diffferent results depending | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-205096@lists.php.net to get a copy of this message | ||
> From: Bogdan Ribic <ribicb@yahoo.com>
> 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.
= has a higher precedence than OR and OR is not the same as ||
http://www.php.net/manual/en/language.operators.php#language.operators.precedence
So you should use
$b1 = is_null($x) || ($y > 5);
---John Holmes...
UCCASS - PHP Survey System
http://www.bigredspark.com/survey.html