php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71319 FILTER_SANITIZE_NUMBER_FLOAT return float instead of string
Submitted: 2016-01-09 12:40 UTC Modified: -
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: Cyb at Cyb10101 dot de Assigned:
Status: Open Package: Filter related
PHP Version: 5.5.31 OS: Ubuntu 14.04
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: Cyb at Cyb10101 dot de
New email:
PHP Version: OS:

 

 [2016-01-09 12:40 UTC] 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)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-01-12 02:16 UTC] 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-12 12:10 UTC] 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
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Nov 12 11:01:31 2019 UTC