Req #75229 [Opn]: FILTER_VALIDATE_INT should allow 0 prefixes
| From: | cmb@php.net | Date: | Wed, 20 Sep 2017 08:31:05 +0000 |
| Subject: | Req #75229 [Opn]: FILTER_VALIDATE_INT should allow 0 prefixes | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-211257@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75229&edit=1
ID: 75229
Updated by: cmb@php.net
Reported by: thflori at gmail dot com
Summary: FILTER_VALIDATE_INT should allow 0 prefixes
Status: Open
Type: Feature/Change Request
Package: Filter related
Operating System: Linux
PHP Version: 7.1.9
Block user comment: N
Private report: N
New Comment:
> This filter is really for properly formatted numbers.
But FILTER_VALIDATE_FLOAT is not? (<https://3v4l.org/OC3UQ>)
Previous Comments:
------------------------------------------------------------------------
[2017-09-19 16:15:36] derick@php.net
I don't believe we should change that. This filter is really for properly formatted numbers.
------------------------------------------------------------------------
[2017-09-19 14:53:58] thflori at gmail dot com
Description:
------------
Someone defined octal numbers are prefixed with a 0 but there is no mathematical theory that says a
number with one or more 0 in front is not a number. When we now use filter_var to filter user input
we have to tell the user that a number with 0 in front is not an integer. Or we use a more generic
way like reg exp /^\d+$/ but I thought the filter_var is made for this propose.
Currently the problem is that users enter minutes and seconds with zeroes in front. It should indeed
not be a float so to filter for integer is correct.
Test script:
---------------
var_dump(filter_var('03', FILTER_VALIDATE_INT));
var_dump(filter_var('+08', FILTER_VALIDATE_INT));
var_dump(filter_var('-010', FILTER_VALIDATE_INT));
Expected result:
----------------
int(3)
int(8)
int(-10)
Actual result:
--------------
false
false
false
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75229&edit=1