Can anyone please explain, why do I get very strange warning:
filter_input() expects parameter 1 to be long, string given
when executing the co
INPUT_POST
and INPUT_GET
are defined as follows:
/**
* POST variables.
* @link http://www.php.net/manual/en/filter.constants.php
*/
define ('INPUT_POST', 0);
/**
* GET variables.
* @link http://www.php.net/manual/en/filter.constants.php
*/
define ('INPUT_GET', 1);
Here the problem. When you concatenate 'INPUT_' with variable it bacame a string, see example:
echo $type = 'INPUT_' . 'POST'; // give you a string INPUT_POST
echo INPUT_POST; //give you 0
That's why :
filter_input() expects parameter 1 to be long, string given
What you're supposed to use there are constants. These constants have integer values. So the documentation is entirely correct, INPUT_GET
is an integer. Try var_dump(INPUT_GET)
.
If you need to get a constant value from a string, use constant()
:
echo constant('INPUT_' . $type);