Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation of filter_input -> return values looks incorrect #4361

Open
salmanarshad2000 opened this issue Jan 6, 2025 · 1 comment
Open

Comments

@salmanarshad2000
Copy link

From manual page: https://php.net/function.filter-input

The Return Value section reads:

On success returns the filtered variable.
If the variable is not set false is returned.
On failure false is returned, unless the FILTER_NULL_ON_FAILURE flag is used, in which case null is returned.

It does not seem to return null when the variable is not set:

$foo = filter_input(INPUT_GET, "x", FILTER_VALIDATE_INT);
var_dump($foo);

The above code produces the following results for the query strings:

localhost/test.php
NULL

localhost/test.php?x=
bool(false)

localhost/test.php?x=asdf
bool(false)

localhost/test.php?x=1234
int(1234)

No flags were set and notice that first case prints NULL. I believe this function always returned NULL if query string/post/cookie/etc variable is not present and the current documentation is incorrect about return values.

@salmanarshad2000
Copy link
Author

salmanarshad2000 commented Jan 7, 2025

An older version of the documentation (Jun 14, 2024) matches the behavior of function:

Value of the requested variable on success, false if the filter fails, or null if the var_name variable is not set. If the flag FILTER_NULL_ON_FAILURE is used, it returns false if the variable is not set and null if the filter fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant