note 108218 added to filter.filters.validate

From: Date: Mon, 09 Apr 2012 10:08:48 +0000
Subject: note 108218 added to filter.filters.validate
Groups: php.notes 
Request: Send a blank email to php-notes+get-187019@lists.php.net to get a copy of this message
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. ---- Server IP: 69.147.83.197 Probable Submitter: 79.212.248.174 ---- Manual Page -- http://www.php.net/manual/en/filter.filters.validate.php Edit -- https://master.php.net/note/edit/108218 Del: integrated -- https://master.php.net/note/delete/108218/integrated Del: useless -- https://master.php.net/note/delete/108218/useless Del: bad code -- https://master.php.net/note/delete/108218/bad+code Del: spam -- https://master.php.net/note/delete/108218/spam Del: non-english -- https://master.php.net/note/delete/108218/non-english Del: in docs -- https://master.php.net/note/delete/108218/in+docs Del: other reasons-- https://master.php.net/note/delete/108218 Reject -- https://master.php.net/note/reject/108218 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#187019) next »