note 100274 deleted from filter.filters.validate by danbrown

From: Date: Tue, 05 Oct 2010 16:16:45 +0000
Subject: note 100274 deleted from filter.filters.validate by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-172980@lists.php.net to get a copy of this message
Note Submitter: Darth Killer ---- 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. ;)

« previous php.notes (#172980) next »