php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57163 Empty string with FILTER_VALIDATE_INT returns 0
Submitted: 2006-07-28 14:08 UTC Modified: 2006-08-31 14:30 UTC
From: Jared dot Williams1 at ntlworld dot com Assigned: pajoye (profile)
Status: Closed Package: filter (PECL)
PHP Version: 5.2.0 RC1 OS: Win200
Private report: No CVE-ID: None
 [2006-07-28 14:08 UTC] Jared dot Williams1 at ntlworld dot com
Description:
------------
An empty string with FILTER_VALIDATE_INT returns 0. I would expect it to return false. 

Reproduce code:
---------------
$var=''; 
var_dump(filter_data($var, FILTER_VALIDATE_INT));

Expected result:
----------------
false

Actual result:
--------------
0

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-28 20:37 UTC] pierre dot php at gmail dot com
I'm not sure it should be false here. I will leave it like that for now. Let see what other people thinks first.
 [2006-08-03 05:23 UTC] x dot philbert at pixandlog dot com
Hello.
It's not a good idea to return false value for empty field.
Why ? If you return false value for empty field, so you don't identify error value.
$test = ''; //return 0
$test2 = 'ABCD'; //return false
If you want identify empty value, use is_empty or isset before filter_data.
You can return a good error message between 'You don't fill the field' and 'You don't correctly answer in field'.
Exemple : What your age ?
Client has answered empty field.
Server test the value (input_get return 0) and return 'Sorry you don't have good age'.
Thank you for your job.
When will out the next release ?
 [2006-08-17 13:28 UTC] philip at roshambo dot org
During testing I assumed it would return false here but assume reasons exist for the 0 instead.  It feels wrong to not know if a user entered in a empty string versus a 0 but I don't offer a strong opinion or solution.
 [2006-08-31 14:30 UTC] pierre dot php at gmail dot com
This bug has been fixed in CVS.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pecl.php.net.

In case this was a pecl.php.net website problem, the change will show
up on the website in short time.
 
Thank you for the report, and for helping us make PECL better.

Got 5 other mails about the same issues, I agree to now :)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 09:01:27 2024 UTC