#42136 [Opn->Bgs]: filter_var() fails for "0"
| From: | pajoye@php.net | Date: | Sun, 29 Jul 2007 10:56:30 +0000 |
| Subject: | #42136 [Opn->Bgs]: filter_var() fails for "0" | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-115527@lists.php.net to get a copy of this message | ||
ID: 42136
Updated by: pajoye@php.net
Reported By: gnupun at yahoo dot com
-Status: Open
+Status: Bogus
Bug Type: Filter related
Operating System: Windows XP
PHP Version: 5.2.3
New Comment:
if (!0) will succeed. That's how PHP works.
You should use:
$filtered = filter_var($myint, FILTER_VALIDATE_INT)
if ($filtered === FALSE)...
There is also an option to return NULL on error.
Previous Comments:
------------------------------------------------------------------------
[2007-07-29 09:38:10] gnupun at yahoo dot com
Description:
------------
filter_var() design is broken... the following code always returns
FALSE:
filter_var() obviously needs two outputs: the filtered value and a
success/failure code.
($value, $errcode) = filter_var(...
Reproduce code:
---------------
$myint = "0";
if (!filter_var($myint, FILTER_VALIDATE_INT)) {
echo "$myint is not an integer\n";
}
else {
echo "$myint is an integer\n";
}
Expected result:
----------------
0 is an integer
Actual result:
--------------
0 is not an integer
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=42136&edit=1