From: Operating system: Debian 5.0.5 PHP version: 5.2.14 Package: Scripting Engine problem Bug Type: Bug Bug description:Logic operator failure
Description: ------------ We found a problem with the logical operators, exactly with the "||" and the "OR" operators. We think both of them are the same, except for the precedence of each one. But when we run the script we show below, the results arent the same. Is not a crash bug, but we found unexpected results using this operators. Thanks in advance Test script: --------------- <?php $a = false; $b = true; $c = true; $res10 = $a || $b || $c; $res11 = ($a || $b) || $c; $res12 = $a || ($b || $c); $res13 = ($a || $b || $c); $res20 = $a OR $b OR $c; $res21 = ($a OR $b) OR $c; $res22 = $a OR ($b OR $c); $res23 = ($a OR $b OR $c); echo ' TEST || <br />'; echo (int)$a." || ".(int)$b." || ".(int)$c." = ".(int)$res10." <br />"; echo "(".(int)$a." || ".(int)$b.") || ".(int)$c." = ".(int)$res11." <br />"; echo (int)$a." || (".(int)$b." || ".(int)$c.") = ".(int)$res12." <br />"; echo "(".(int)$a." || ".(int)$b." || ".(int)$c.") = ".(int)$res13." <br />"; echo ' <br />'; echo ' TEST OR<br />'; echo (int)$a." OR ".(int)$b." OR ".(int)$c." = ".(int)$res20." <br />"; echo "(".(int)$a." OR ".(int)$b.") OR ".(int)$c." = ".(int)$res21." <br />"; echo (int)$a." OR (".(int)$b." OR ".(int)$c.") = ".(int)$res22." <br />"; echo "(".(int)$a." OR ".(int)$b." OR ".(int)$c.") = ".(int)$res23." <br />"; ?> Expected result: ---------------- We except the same result for all the comparators. We think it must be "true" all of them Actual result: -------------- The result is unexpected. The result is not the same using an "OR" or a "||", but it must be the same. is not a precedence problem because we are using only one operator at the same time. -- Edit bug report at http://bugs.php.net/bug.php?id=53015&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=53015&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=53015&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=53015&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=53015&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=53015&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=53015&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=53015&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=53015&r=needscript Try newer version: http://bugs.php.net/fix.php?id=53015&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=53015&r=support Expected behavior: http://bugs.php.net/fix.php?id=53015&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=53015&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=53015&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=53015&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53015&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=53015&r=dst IIS Stability: http://bugs.php.net/fix.php?id=53015&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=53015&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=53015&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=53015&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=53015&r=mysqlcfg