Bug #69226 [Com]: FILTER_VALIDATE_FLOAT treats integers as floats

From: Date: Tue, 17 Mar 2015 21:51:41 +0000
Subject: Bug #69226 [Com]: FILTER_VALIDATE_FLOAT treats integers as floats
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191438@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
 Comment by:         cmbecker69 at gmx dot de
 Reported by:        ianbytchek at gmail dot com
 Summary:            FILTER_VALIDATE_FLOAT treats integers as floats
 Status:             Open
 Type:               Bug
 Package:            Filter related
 Operating System:   OS X 10.10.2
 PHP Version:        5.6.6
 Block user comment: N
 Private report:     N

 New Comment:

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?


Previous Comments:
------------------------------------------------------------------------
[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


Thread (2 messages)

« previous php.bugs (#191438) next »