Skip to content

Documentation of filter_input -> return values looks incorrect #4361

@salmanarshad2000

Description

@salmanarshad2000

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions