Bug #66682 [Com]: FILTER_VALIDATE_INT fails on strings starting with zero.

From: Date: Sun, 16 Feb 2014 16:23:04 +0000
Subject: Bug #66682 [Com]: FILTER_VALIDATE_INT fails on strings starting with zero.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184322@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66682&edit=1 ID: 66682 Comment by: alex dot howansky at gmail dot com Reported by: alex dot howansky at gmail dot com Summary: FILTER_VALIDATE_INT fails on strings starting with zero. Status: Not a bug Type: Bug Package: Filter related Operating System: Linux 2.6 64 PHP Version: 5.5.9 Block user comment: N Private report: N New Comment: > Please double-check the documentation I'm unable to find any documentation that contradicts my evaluation or explains this behavior. Can you please link to the specific page you're referring to? I'm confused by the hex/oct comment -- whether or not "01" is interpreted as octal or hex doesn't change the fact that it's still a valid value for an integer. I.e., "01" octal is a valid int, "01" hex is a valid int, and "01" decimal is a valid int. Also, if I plug "01" into any other function that expects an integer, it will work just fine. Consider this: var_dump(abs('01')); var_dump(intval('01')); var_dump(octdec('01')); var_dump(hexdec('01')); var_dump(filter_var('01' + '0.0', FILTER_VALIDATE_INT)); var_dump(filter_var('01', FILTER_VALIDATE_INT)); Returns: int(1) int(1) int(1) int(1) int(1) bool(false) Don't you think that output is rather contradictory? Previous Comments: ------------------------------------------------------------------------ [2014-02-16 11:55:43] derick@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php This is by design. ------------------------------------------------------------------------ [2014-02-16 06:24:58] yohgaki@php.net php_filter_parse_int() does not allow leading 0 ------------------------------------------------------------------------ [2014-02-16 06:15:48] yohgaki@php.net This is because php_fileter_int() treats leading 0 as hex/octal numbers. I'm not sure which one int or float should be fixed. Possible fix is https://github.com/yohgaki/php-src/compare/PHP-5.4-bug66682 ------------------------------------------------------------------------ [2014-02-10 05:40:33] alex dot howansky at gmail dot com Description: ------------ FILTER_VALIDATE_INT fails on '01'. I can understand that opinions might be divided on whether this should return 1 or false -- however, in either case, the behavior of FILTER_VALIDATE_FLOAT should match, and it doesn't. Test script: --------------- var_dump(filter_var('01', FILTER_VALIDATE_INT)); var_dump(filter_var('01', FILTER_VALIDATE_FLOAT)); Expected result: ---------------- int(1) double(1) or: bool(false) bool(false) Actual result: -------------- bool(false) double(1) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=66682&edit=1

« previous php.bugs (#184322) next »