Bug->Doc #69226 [Opn]: FILTER_VALIDATE_FLOAT treats integers as floats
| From: | ianbytchek at gmail dot com | Date: | Tue, 17 Mar 2015 22:16:46 +0000 |
| Subject: | Bug->Doc #69226 [Opn]: FILTER_VALIDATE_FLOAT treats integers as floats | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-12006@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69226&edit=1
ID: 69226
User updated by: ianbytchek at gmail dot com
Reported by: ianbytchek at gmail dot com
Summary: FILTER_VALIDATE_FLOAT treats integers as floats
Status: Open
-Type: Bug
+Type: Documentation Problem
Package: Filter related
Operating System: OS X 10.10.2
PHP Version: 5.6.6
Block user comment: N
Private report: N
New Comment:
Sorry, I agree that float having a decimal point is about something else. Out of nowhere I got
confused about it and was carried away having wrong ideas. My bad.
> Well, I appreciate the current behavior. If the given value
> validates as float, why not convert it to a float right away?
This is a feature bug at best without the documentation :) I guess this is a good thing,
alternatively we can use the original value, if we want it as string.
http://fc04.deviantart.net/fs71/f/2011/315/f/7/f763312cf3b15d96718db268c39edebf-d2z0z5x.jpg
Can documentation be updated where the returned value differs from original? I guess it's only
integer and float? Boolean already mentions that the boolean is returned.
http://php.net/manual/en/filter.filters.validate.php
Previous Comments:
------------------------------------------------------------------------
[2015-03-17 21:51:40] cmbecker69 at gmx dot de
IMO this is not a bug, because filter_var()'s behavior is well
aligned with PHP's type juggling. Consider:
var_dump((float) '10'); // double(10)
> Floats are numbers with a floating point.
No, at least not in the sense that a decimal mark has to be part
of the string representation of a floating point number. Consider
the example above, or:
var_dump(1e2); // double(100)
If you need to validate that a given input contains a decimal point,
you could use FILTER_VALIDATE_REGEXP with an appropriate regex.
> Also, why does filter convert value from string into an actual
> number? Shouldn't that be done only by sanitize filters?
Well, I appreciate the current behavior. If the given value
validates as float, why not convert it to a float right away?
------------------------------------------------------------------------
[2015-03-12 00:06:47] ianbytchek at gmail dot com
Description:
------------
I might be missing something here, but⦠Floats are numbers with a floating point. For example:
```
$x = 10;
$x === (float) $x; // false
(float) $x === (float) $x; // true
```
But FILTER_VALIDATE_FLOAT treats integers as floats. Both examples below must return false.
```
filter_var($x, FILTER_VALIDATE_FLOAT) // 10
filter_var('10', FILTER_VALIDATE_FLOAT) // 10
```
Also, why does filter convert value from string into an actual number? Shouldn't that be done
only by sanitize filters?
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69226&edit=1