php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53015 Logic operator failure
Submitted: 2010-10-07 19:21 UTC Modified: 2010-10-08 02:23 UTC
From: jesus dot perez at infpormax dot es Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.14 OS: Debian 5.0.5
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jesus dot perez at infpormax dot es
New email:
PHP Version: OS:

 

 [2010-10-07 19:21 UTC] jesus dot perez at infpormax dot es
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.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-07 19:23 UTC] jesus dot perez at infpormax dot es
There are a mistake at the email address
it must be 
jesus.perez@informax.es
My apologies for the inconveniences
 [2010-10-08 02:23 UTC] cataphract@php.net
-Status: Open +Status: Bogus
 [2010-10-08 02:23 UTC] cataphract@php.net
This is indeed a problem of precedence. In particular, the precedence of = is bigger than the precedence of OR.

Closing as bogus.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 22 15:00:02 2025 UTC