note 119528 added to filter.filters.validate
| From: | kizge | Date: | Thu, 30 Jun 2016 08:18:04 +0000 |
| Subject: | note 119528 added to filter.filters.validate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-205839@lists.php.net to get a copy of this message | ||
FILTER_VALIDATE_INT first casts its value to string which produces unexpected result for bool and
float (https://bugs.php.net/bug.php?id=72490):
<?php
// Prints int(1).
var_dump(filter_var(true, FILTER_VALIDATE_INT));
// ...but this prints bool(false).
var_dump(filter_var(false, FILTER_VALIDATE_INT));
// --------
// Prints bool(false).
var_dump(filter_var(1.1, FILTER_VALIDATE_INT));
// ...but this prints int(0).
var_dump(filter_var(0.0, FILTER_VALIDATE_INT));
// ...but this again is bool(false).
var_dump(filter_var('0.0', FILTER_VALIDATE_INT));
// Also bool(false).
var_dump(filter_var('-0.0', FILTER_VALIDATE_INT));
?>
Live sample: https://3v4l.org/CZW0W
The docs are not clear on how exactly this casting affects the result for certain input values.
----
Server IP: 72.52.91.14
Probable Submitter: 94.242.243.231
----
Manual Page -- http://php.net/manual/en/filter.filters.validate.php
Edit -- https://master.php.net/note/edit/119528
Del: integrated -- https://master.php.net/note/delete/119528/integrated
Del: useless -- https://master.php.net/note/delete/119528/useless
Del: bad code -- https://master.php.net/note/delete/119528/bad+code
Del: spam -- https://master.php.net/note/delete/119528/spam
Del: non-english -- https://master.php.net/note/delete/119528/non-english
Del: in docs -- https://master.php.net/note/delete/119528/in+docs
Del: other reasons-- https://master.php.net/note/delete/119528
Reject -- https://master.php.net/note/reject/119528
Search -- https://master.php.net/manage/user-notes.php