Doc #69226 [Ver->Csd]: FILTER_VALIDATE_FLOAT treats integers as floats

From: Date: Mon, 31 Aug 2015 23:10:15 +0000
Subject: Doc #69226 [Ver->Csd]: FILTER_VALIDATE_FLOAT treats integers as floats
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-12689@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 Updated by: cmb@php.net Reported by: ianbytchek at gmail dot com Summary: FILTER_VALIDATE_FLOAT treats integers as floats -Status: Verified +Status: Closed Type: Documentation Problem Package: Filter related Operating System: OS X 10.10.2 PHP Version: 5.6.6 Assigned To: cmb Block user comment: N Private report: N New Comment: This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. Previous Comments: ------------------------------------------------------------------------ [2015-08-31 23:09:49] cmb@php.net Automatic comment from SVN on behalf of cmb Revision: http://svn.php.net/viewvc/?view=revision&revision=337683 Log: clarified converting behavior of FILTER_VALIDATE_(FLOAT|INT) (fixes #69226) ------------------------------------------------------------------------ [2015-08-31 23:05:14] cmb@php.net I agree that the docs can be improved. BTW: you could do filter_var('10', FILTER_VALIDATE_FLOAT, [options=>['decimal'=>true]]) ------------------------------------------------------------------------ [2015-03-17 22:16:45] ianbytchek at gmail dot com 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 ------------------------------------------------------------------------ [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

« previous php.doc.bugs (#12689) next »