note 130443 added to function.filter-var
| From: | neil@digital-illusion.net | Date: | Mon, 04 Aug 2025 11:54:06 +0000 |
| Subject: | note 130443 added to function.filter-var | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-222302@lists.php.net to get a copy of this message | ||
var_dump(filter_var(null, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)); <- returns false
you would expect this to return null because it uses FILTER_NULL_ON_FAILURE
"On success returns the filtered data. On failure false is returned, unless the
FILTER_NULL_ON_FAILURE flag is used, in which case null is returned."
The filter_var() function first coerces null to an empty string before applying the filter so it is
actually doing
var_dump(filter_var('', FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)); <- returns
false
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 62.30.203.184)
----
Manual Page -- https://php.net/manual/en/function.filter-var.php
Edit -- https://main.php.net/note/edit/130443
Del: integrated -- https://main.php.net/note/delete/130443/integrated
Del: useless -- https://main.php.net/note/delete/130443/useless
Del: bad code -- https://main.php.net/note/delete/130443/bad+code
Del: spam -- https://main.php.net/note/delete/130443/spam
Del: non-english -- https://main.php.net/note/delete/130443/non-english
Del: in docs -- https://main.php.net/note/delete/130443/in+docs
Del: other reasons-- https://main.php.net/note/delete/130443
Reject -- https://main.php.net/note/reject/130443
Search -- https://main.php.net/manage/user-notes.php