Add examples for filter_var_array() and filter_input_array() - #5267
Merged
Conversation
lacatoire
force-pushed
the
docs/filter-array-examples
branch
3 times, most recently
from
August 21, 2026 10:00
8844be6 to
93533c0
Compare
lacatoire
force-pushed
the
docs/filter-array-examples
branch
from
August 25, 2026 10:01
4719079 to
0eacf63
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4218
Add examples for
filter_var_array()andfilter_input_array(), and correct the descriptions that those examples contradicted.filter_var_array()gains two examples next to the existing one: applying a single filter to every entry of the array, andFILTER_CALLBACK.filter_input_array()had no examples at all and gains three: filtering GET input, filtering POST input (including a field that was not submitted, to show whatadd_emptydoes), and requesting an input type that is not populated.Writing those examples surfaced several inaccuracies in the surrounding prose, corrected here:
filter_input_array()returnsnull, notfalse, when the input array designated bytypeis not populated. This does not depend on any flag.nullwhenadd_emptyis true. TheFILTER_NULL_ON_FAILUREflag does not turn it intofalse; that inversion applies tofilter_input(), not to the array form.filter_var_array()had no mention ofadd_emptyorFILTER_NULL_ON_FAILUREin its return values, and stated that a failing entry isfalsewithout either qualifier.FILTER_FORCE_ARRAY, the failure value is wrapped in a one element array like any other result.optionsdescription is shared withfilter_input_array()throughxi:include, but referred to$array, a parameter that only exists onfilter_var_array().FILTER_REQUIRE_SCALARis the default for both functions, so the flag in the first example only restates it. Said so, rather than leaving it to look like it changes the outcome.optionsdescription: "specifies and flags".All outputs were reproduced on PHP 8.4.24, the request-dependent ones through the built-in web server.
Sources
nullreturned whenever the input array is absent, independently of any flag:ext/filter/filter.c,PHP_FUNCTION(filter_input_array),if (!array_input) { RETURN_NULL(); }null:ext/filter/filter.c,php_filter_array_handler(),add_assoc_null_ex()is reached without the flags being readFILTER_REQUIRE_SCALARreinstated as the default whenever no*_ARRAYflag is given:ext/filter/filter.c,php_filter_call()