Bug #3465: erroneous comparison of intval() return value

From: Date: Sat, 12 Feb 2000 03:51:44 +0000
Subject: Bug #3465: erroneous comparison of intval() return value
Groups: php.dev 
Request: Send a blank email to php-dev+get-15416@lists.php.net to get a copy of this message
From: zeekamotay@hotmail.com Operating system: Linux 2.2.x PHP version: 3.0.14 PHP Bug Type: Other Bug description: erroneous comparison of intval() return value I'm trying to tell the difference between a string value and an integer value -- not a string type variable and an integer type variable. I.e., if a string type variable contains the value "503", I want to consider it an integer. So, I use intval(), figuring that if the intval() of a variable is the same as the value of the variable, then the variable has an integer value. For example, if $x = "503", then intval($x) = 503. So, $x == intval($x) and I consider it an integer. If $x = "this is a test", then intval($x) is 0. Since $x != intval($x), I don't consider it an integer. Here's the part I don't understand: <? $x = "this is a test"; echo "<p>\$x = " . $x; echo "<p>intval(\$x) = " . intval($x); if ($x == intval($x)) { echo "<p>\$x is an int"; } ?> The output of this script is: $x = this is a test intval($x) = 0 $x is an int How the heck is $x == intval($x) if $x = "this is a test" and intval($x) = 0?

« previous php.dev (#15416) next »