note 100274 added to filter.filters.validate
| From: | DarthKiller at osu1 dot php dot net | Date: | Tue, 05 Oct 2010 16:15:09 +0000 |
| Subject: | note 100274 added to filter.filters.validate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-172979@lists.php.net to get a copy of this message | ||
If i may answer to pravila next to me.
The FILTER_NULL_ON_FAILURE flag is not set by default with filter_input() and filter_input_array(),
as if you try the code bellow nothing will change, despite trying to cancel the flag with the ~
bitwise operator
URL : example.com/script.php?arg1=yes&arg3=no
<?php
// filtering by input
$input1 = filter_input(INPUT_GET, "arg1", FILTER_VALIDATE_BOOLEAN,
~FILTER_NULL_ON_FAILURE);
$input2 = filter_input(INPUT_GET, "arg2", FILTER_VALIDATE_BOOLEAN,
~FILTER_NULL_ON_FAILURE);
$input3 = filter_input(INPUT_GET, "arg3", FILTER_VALIDATE_BOOLEAN,
~FILTER_NULL_ON_FAILURE);
// as expected...
var_dump($var1); // bool(true)
var_dump($var2); // bool(false)
var_dump($var3); // bool(false)
// NULL is not an expected return...
var_dump($input1); // bool(true)
var_dump($input2); // NULL
var_dump($input3); // bool(false)
?>
The truth is that if the input data doesn't exist, filter_input() and filter_input_array() will
return NULL without even trying to apply the chosen filter. That's why your second test returns
NULL instead of bool(false).
Try FILTER_CALLBACK if this is an issue that troubles you for your script. ;)
----
Server IP: 89.31.146.176
Probable Submitter: 85.69.114.238
----
Manual Page -- http://www.php.net/manual/en/filter.filters.validate.php
Edit -- https://master.php.net/note/edit/100274
Del: integrated -- https://master.php.net/note/delete/100274/integrated
Del: useless -- https://master.php.net/note/delete/100274/useless
Del: bad code -- https://master.php.net/note/delete/100274/bad+code
Del: spam -- https://master.php.net/note/delete/100274/spam
Del: non-english -- https://master.php.net/note/delete/100274/non-english
Del: in docs -- https://master.php.net/note/delete/100274/in+docs
Del: other reasons-- https://master.php.net/note/delete/100274
Reject -- https://master.php.net/note/reject/100274
Search -- https://master.php.net/manage/user-notes.php