note 108218 deleted from filter.filters.validate by cmb
| From: | cmb@php.net | Date: | Fri, 21 Aug 2015 21:43:10 +0000 |
| Subject: | note 108218 deleted from filter.filters.validate by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-203414@lists.php.net to get a copy of this message | ||
Note Submitter: Tom
----
Be aware!
In contrary to what the docs say (at least in PHP 5.3.1), this line:
$value = filter_var(FALSE, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
Will return NULL - not false. In other words: a boolean FALSE is not considered a valid boolean
value by this function.
Also:
$value = filter_var("", FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
Will also return NULL - no matter what the docs say. So (string) FALSE is not considered a valid
boolean input either.
Thus be aware the that correct usage/workaround for this filter is:
if (!is_bool($value)) {
$value= filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
}
For those of you who feel this is counterintuitive, note that there is an issue filed for this in
the bug-tracker.
So you might want to follow the discussion there or vote for issue #49510.