Bug #71319 [Opn->Nab]: FILTER_SANITIZE_NUMBER_FLOAT return float instead of string
| From: | cmb@php.net | Date: | Thu, 04 Jun 2020 12:49:27 +0000 |
| Subject: | Bug #71319 [Opn->Nab]: FILTER_SANITIZE_NUMBER_FLOAT return float instead of string | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-227318@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71319&edit=1
ID: 71319
Updated by: cmb@php.net
Reported by: Cyb at Cyb10101 dot de
Summary: FILTER_SANITIZE_NUMBER_FLOAT return float instead of
string
-Status: Open
+Status: Not a bug
Type: Bug
Package: Filter related
Operating System: Ubuntu 14.04
PHP Version: 5.5.31
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
FILTER_SANITIZE_NUMBER_FLOAT behaves as documented[1]:
| Remove all characters except digits, +- and optionally .,eE.
It does not return a float, because the result is not guaranteed
to be a valid numer, e.g. <https://3v4l.org/Kc0q7>.
[1] <https://www.php.net/manual/en/filter.filters.sanitize.php>
Previous Comments:
------------------------------------------------------------------------
[2016-01-12 12:10:04] Cyb at Cyb10101 dot de
I just think, as soon as I have a float or integer, it does not make much sense to have a string.
Finally, it is indeed cleaned, so you get a float or not?
Of course, there can convert with floatval.
That's why I'm not sure.
http://php.net/manual/de/function.floatval.php
------------------------------------------------------------------------
[2016-01-12 02:16:56] vadz77 at hotmail dot com
I don't think this is a bug.
FILTER_SANITIZE_NUMBER_FLOAT should just sanitize a
string and return as a string. E.g. http://codepad.org/T690Wdad
------------------------------------------------------------------------
[2016-01-09 12:40:05] Cyb at Cyb10101 dot de
Description:
------------
Hi, I'm not sure if that's a bug.
The function filter_var($x, FILTER_SANITIZE_NUMBER_FLOAT) should not return a float instead string?
Kind regards, Cyb10101
Test script:
---------------
<?php
function d($a = '', $x, $z = ' | ') {echo $a; var_dump($x); echo $z;}
function run($x) {
d('init=', $x);
d('bool=', (filter_var($x, FILTER_VALIDATE_FLOAT) ? 'Valid' : 'Not
Valid'));
d('validate=', filter_var($x, FILTER_VALIDATE_FLOAT));
d('sanitize=', filter_var($x, FILTER_SANITIZE_NUMBER_FLOAT), "<br />\n");
}
run(0.5); // init=float(0.5) | bool=string(5) "Valid" | validate=float(0.5) |
sanitize=string(2) "05"
run('0.5'); // init=string(3) "0.5" | bool=string(5) "Valid" |
validate=float(0.5) | sanitize=string(2) "05"
Expected result:
----------------
run(0.5); // ... | sanitize=float(0.5)
run('0.5'); // ... | sanitize=float(0.5)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71319&edit=1