From: cleo at anarki dot dk
Operating system: WinXP, Mandriva Linux 2006
PHP version: 5.1.2
PHP Bug Type: *General Issues
Bug description: Short cirquit AND evaluates like OR
Description:
------------
Consider the following piece of code:
$res= ($h>=0) and ($h<=23);
It could be used to determine if a user has submitted an hour between 0
and 23.
However, if the user enters 25, then the function evaluates to true!!!!
If you reverse the order of the operands like this:
$res = ($h<=23) and ($h>=0);
...then a $h value of 25 will make the function evaluate to false.
But now -1 will make it evaluate to true!
So clearly, this must be a major bug.
Best regards
Claus Holm, Copenhagen, Denmark
Reproduce code:
---------------
<? if (isset($_POST['test'])) {
$hours= $_POST['e_hours'];
$hours= (integer)$hours;
echo "You entered $hours <br>";
echo 'Now we test: ($hours>=0) and ($hours<=23)<br>';
$test1= ($hours>=0) and ($hours<=23);
echo $test1 ? "ok" : "nope";
echo "<br>";
echo 'And now we test: ($hours<=23)and($hours>=0)<br>';
$test2= ($hours<=23) and ($hours>=0);
echo $test2 ? "ok" : "nope";
}
else {
?> Input an hour between 0 and 23:<br>
<FORM action="<?=$_SERVER['PHP_SELF']?>" method="post">
<INPUT type="text" name="e_hours" value=""><br>
<INPUT type="submit" name="test" value="Run test">
</form>
<?}
?>
Expected result:
----------------
If the value 25 is entered, then I should see this:
You entered 25
Now we test: ($hours>=0) and ($hours<=23)
nope
And now we test: ($hours<=23) and ($hours>=0)
nope
Actual result:
--------------
You entered 25
Now we test: ($hours>=0) and ($hours<=23)
ok
And now we test: ($hours<=23) and ($hours>=0)
nope
--
Edit bug report at http://bugs.php.net/?id=36799&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=36799&r=trysnapshot44
Try a CVS snapshot (PHP 5.1):
http://bugs.php.net/fix.php?id=36799&r=trysnapshot51
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=36799&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=36799&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=36799&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=36799&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=36799&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=36799&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=36799&r=support
Expected behavior: http://bugs.php.net/fix.php?id=36799&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=36799&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=36799&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=36799&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=36799&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=36799&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=36799&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=36799&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=36799&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=36799&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=36799&r=mysqlcfg