I use filter_input_array
PHP function when sanitizing data inputs in my application. Consider example below:
public function acquireData()
{
$args = array(
'model' => FILTER_SANITIZE_STRING,
);
//function that sanitizes input from POST
$output = filter_input_array(INPUT_POST, $args);
return $output;
}
It works fine when I read live POST data from a web browser. But when I want to pass in another array for the purposes of testing I struggle to find a solution.
i.e. using my own array does not work and produces empty $output
:
$myInputArray = array('model' => 'ABC'); //with same parameters as $_POST
$output = filter_input_array($myInputArray, $args);
//$output is null;
Note
I want to specifically use INPUT_POST
construct. Or get an answer "it is not possible" or "you can only seek work-arounds".
i.e. using filter_var_array
is a work-around, because it does not use INPUT_POST
. Example work-around below:
$output = filter_var_array($_POST, $args);