#30689 [Csd->Bgs]: logical operators not working as expected
| From: | tony2001@php.net | Date: | Tue, 16 Nov 2004 05:52:04 +0000 |
| Subject: | #30689 [Csd->Bgs]: logical operators not working as expected | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-69121@lists.php.net to get a copy of this message | ||
ID: 30689
Updated by: tony2001@php.net
Reported By: ioan dot nicu at ines dot ro
-Status: Closed
+Status: Bogus
Bug Type: Zend Engine 2 problem
Operating System: Linux
PHP Version: 4CVS-2004-11-04 (stable)
Previous Comments:
------------------------------------------------------------------------
[2004-11-16 00:22:24] ioan dot nicu at ines dot ro
Sorry, you are right.
I'm closing this bug report.
------------------------------------------------------------------------
[2004-11-04 20:58:47] derick@php.net
No bug here, the = operator has a higher precedence than and, or and
xor so you'll have to use parenthesis. See:
http://www.php.net/manual/en/language.operators.php#language.operators.precedence
------------------------------------------------------------------------
[2004-11-04 18:54:14] ioan dot nicu at ines dot ro
Description:
------------
The logical operators 'and', 'or', 'xor' have unexpected
results. The bug doesn't occur when using C-style logical
operators ( ||, &&, ^^).
From the php manual (Logical Operators Section):
http://www.php.net/manual/en/language.operators.logical.php
Example | Name | Result
--------------------------------------------------
$a and $b | And | TRUE if both $a and $b are TRUE.
$a or $b | Or | TRUE if either $a or $b is TRUE.
$a xor $b | Xor | TRUE if either $a or $b is TRUE, but not both.
This bug is reproducible on the latest stable snapshot from
cvs.
Reproduce code:
---------------
<?
$a1 = false or true; $a2 = true or false;
$b1 = true or false; $b2 = false and true;
$c = true xor true;
echo("false or true = ");var_dump($a1);
echo("true or false = ");var_dump($a2);
echo("true and false = ");var_dump($b1);
echo("false and true = ");var_dump($b2);
echo("true xor true = ");var_dump($c);
?>
Expected result:
----------------
false or true = bool(true)
true or false = bool(true)
true and false = bool(false)
false and true = bool(false)
true xor true = bool(false)
Actual result:
--------------
false or true = bool(false)
true or false = bool(true)
true and false = bool(true)
false and true = bool(false)
true xor true = bool(true)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=30689&edit=1