Edit report at https://bugs.php.net/bug.php?id=43372&edit=1
ID: 43372 Updated by: ras...@php.net Reported by: gbml at bravogroup dot org Summary: FILTER_VALIDATE_INT returns null for numbers with leading zero(s) Status: Not a bug Type: Bug Package: Filter related Operating System: linux PHP Version: 5.2.5 Assigned To: pajoye Block user comment: N Private report: N New Comment: How is it ludicrous? You understand that 08 is an invalid value in octal, right? The filters are all about filtering out invalid input. If you specify you want valid integers (which are in decimal notation by default) and you also say you want to accept integers in octal notation, then it *must* return false on a value which is neither an octal nor a decimal representation of an integer. Previous Comments: ------------------------------------------------------------------------ [2013-08-05 16:21:18] kodafixed at gmail dot com That assumes one has control over the input. If for example, the input data comes from a form submission then it may in fact come into the program with leading zero(es). In order to make the data in this scenario "valid" for the test you would have to cast it or manipulate it - which makes using the built-in function moot. The concept that filter_var('8', FILTER_VALIDATE_INT, FILTER_FLAG_ALLOW_OCTAL) should return 8, but filter_var('08', FILTER_VALIDATE_INT, FILTER_FLAG_ALLOW_OCTAL) should return false is ludicrous. ------------------------------------------------------------------------ [2013-08-05 15:41:28] ras...@php.net Don't use FILTER_VALIDATE_INT if you don't want to validate decimal notation integers. Decimal notation integers do not have a leading 0, except for 0 itself, of course. If you just want a filter that checks if the input is entirely made of digits, just use a regex. eg. filter_var($string, FILTER_VALIDATE_REGEXP, ["options"=>["regexp"=>"/^[0- 9]+$/"]]); ------------------------------------------------------------------------ [2013-08-05 14:05:50] kodafixed at gmail dot com FILTER_FLAG_ALLOW_OCTAL is not a feasible workaround for this issue. echo filter_var('08', FILTER_VALIDATE_INT, FILTER_FLAG_ALLOW_OCTAL) ? "OKAY" : "NOT OKAY"; // RESULT: "NOT OKAY" FILTER_FLAG_ALLOW_OCTAL completely invalidates tests where the value has a leading 0 and includes an 8 or 9. ------------------------------------------------------------------------ [2007-11-22 11:13:09] paj...@php.net See FILTER_FLAG_ALLOW_OCTAL. ------------------------------------------------------------------------ [2007-11-22 10:54:54] gbml at bravogroup dot org Description: ------------ Filtering input numbers with leading zero(s) and filter FILTER_VALIDATE_INT does not produce number Reproduce code: --------------- // $_POST ["size"] has value "002" filter_input (INPUT_POST, "size", FILTER_VALIDATE_INT) Expected result: ---------------- 2 Actual result: -------------- null ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=43372&edit=1