|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-01-06 16:28 UTC] ivo at benetech dot org
Description:
------------
The statement...
if("NANC" < 0)
...always evaluates TRUE.
Reproduce code:
---------------
if("NANC" < 0)
{
print("should not happen...but does\n");
}
else
{
print("should happen...but doesnt\n");
}
Expected result:
----------------
echoed to the console:
should happen...but doesnt
Actual result:
--------------
echoed to the console:
should not happen...but does
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 11:00:01 2025 UTC |
"NANC" is converted to 0 for comparison. It works for me as expected. What is printed by the code <?php echo intval("NANC"); ?> on your system?As said by sniper: never ever compare different types like that!!! In case $var is an int, you can do a $var < 0. In case $var is a string, PHP don't know what to do (try this with Java or C++!). Let your called functions return FALSE on error and everything works fine. Or as an alternative, try something like $var=somefunction(); if(is_integer($var)&&$var<0) { // Here comes the error-Processing print("Error\n"); } else { // Do something with $var print $var; }