Bug #68551 [Opn->Nab]: filter_var return false for (float) $integer if strlen($integer) > ini_get('prec

From: Date: Fri, 05 Dec 2014 14:43:45 +0000
Subject: Bug #68551 [Opn->Nab]: filter_var return false for (float) $integer if strlen($integer) > ini_get('prec
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-188933@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68551&edit=1 ID: 68551 Updated by: ajf@php.net Reported by: frederic dot hardy at mageekbox dot net Summary: filter_var return false for (float) $integer if strlen($integer) > ini_get('prec -Status: Open +Status: Not a bug Type: Bug Package: Filter related Operating System: Linux/OSX PHP Version: 5.6.3 Block user comment: N Private report: N New Comment: 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 filter_var's FILTER_VALIDATE_INT always casts its argument to a string before conversion, and exponents and decimal points are never accepted, this is no exception. Previous Comments: ------------------------------------------------------------------------ [2014-12-05 12:54:16] frederic dot hardy at mageekbox dot net Description: ------------ filter_var() with option FILTER_VALIDATE_INT return false if its argument is an integer casted to float with strlen($integer) > ini_get('precision'). Test script: --------------- <?php ini_set('precision', 14); // PHP default $i = 12345678912345; // strlen($i) == 14 var_dump(strlen($i)); var_dump(filter_var((float) $i, FILTER_VALIDATE_INT)); // $i var_dump((float) $i == $i); // true $i = 123456789123456; // strlen($i) = 15 var_dump(strlen($i)); var_dump(filter_var((float) $i, FILTER_VALIDATE_INT)); // false instead of $i var_dump((float) $i == $i); // true Expected result: ---------------- int(14) int(12345678912345) bool(true) int(15) bool(123456789123456) bool(true) Actual result: -------------- int(14) int(12345678912345) bool(true) int(15) bool(false) bool(true) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=68551&edit=1

« previous php.bugs (#188933) next »