|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-03-20 18:09 UTC] tony2001@php.net
[2006-03-20 19:59 UTC] cleo at anarki dot dk
[2006-03-20 20:05 UTC] tony2001@php.net
[2006-03-21 01:59 UTC] rasmus@php.net
[2006-03-21 09:18 UTC] cleo at anarki dot dk
[2006-03-21 10:11 UTC] rasmus@php.net
[2006-03-21 19:33 UTC] cleo at anarki dot dk
[2006-03-21 19:54 UTC] rasmus@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 10:00:01 2025 UTC |
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