Bug #68551 [Nab->Opn]: filter_var return false for (float) $integer if strlen($integer) > ini_get('prec
| From: | pajoye@php.net | Date: | Thu, 11 Dec 2014 02:42:14 +0000 |
| Subject: | Bug #68551 [Nab->Opn]: 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-189002@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: pajoye@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: Not a bug
+Status: Open
Type: Bug
Package: Filter related
Operating System: Linux/OSX
PHP Version: 5.6.3
Block user comment: N
Private report: N
New Comment:
Actually there are non sense inconsistencies here, due to the precision setting and conversion. Due
to this, some dots may be accepted and other not if the length of the string representation of the
value is bigger than the precision setting. This is a bug.
Previous Comments:
------------------------------------------------------------------------
[2014-12-10 14:05:11] frederic dot hardy at mageekbox dot net
Moreover, to be clear:
<?php
ini_set('precision', 2);
$i = 100;
var_dump(filter_var((float) $i, FILTER_VALIDATE_INT)); // bool(false)
var_dump((float) $i == $i); // bool(true)
?>
So, how a float can be equal to an integer if it's not an integer ?
------------------------------------------------------------------------
[2014-12-10 13:33:41] frederic dot hardy at mageekbox dot net
Pierre just say me on IRC to add this script to illustrate the problem:
<?php
ini_set('precision', 2);
var_dump(filter_var(1.0, FILTER_VALIDATE_INT)); // int(1)
var_dump(filter_var(100.0, FILTER_VALIDATE_INT)); // bool(false)
?>
So, filter_var(1.0, FILTER_VALIDATE_INT) should return false, as filter_var(100.0,
FILTER_VALIDATE_INT), or filter_var(100.0, FILTER_VALIDATE_INT) should return int(100)...
------------------------------------------------------------------------
[2014-12-05 18:58:18] frederic dot hardy at mageekbox dot net
So, filter_validate(1., FILTER_VALIDATE_INT) return (int) 1, but filter_validate(123456789123456.,
FILTER_VALIDATE_INT) return false, and it's not a bug. OK. All is right, we are in the PHP
world!
------------------------------------------------------------------------
[2014-12-05 14:44:38] ajf@php.net
(Though I agree it's pretty weird behaviour, FILTER_VALIDATE_INT could seriously be improved.
Still, it's not actually a bug.)
------------------------------------------------------------------------
[2014-12-05 14:43:45] ajf@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
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.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=68551
--
Edit this bug report at https://bugs.php.net/bug.php?id=68551&edit=1