ext/filter: Narrow the return type of filter_var_array() to array|false - #23403
Open
lacatoire wants to merge 1 commit into
Open
ext/filter: Narrow the return type of filter_var_array() to array|false#23403lacatoire wants to merge 1 commit into
lacatoire wants to merge 1 commit into
Conversation
The stub declares array|false|null, but null is unreachable. The function has two exits: RETURN_FALSE for an unknown filter id, and the array handler, which establishes an array on both of its branches before doing anything else. Its remaining exits throw. The sibling filter_input_array() is declared identically and does return null, deliberately, because its source superglobal may not exist. That case has no equivalent here, where the source is a required array parameter. null remains an ordinary element value in the returned array, which is likely where the wider union came from; that is the value type, not the return type.
LamentXU123
requested changes
Aug 21, 2026
LamentXU123
left a comment
Member
There was a problem hiding this comment.
Hi, In zend_func_infos.h L98
F1("filter_var_array", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY|MAY_BE_ARRAY_OF_REF|MAY_BE_FALSE|MAY_BE_NULL),
MAY_BE_NULL is still in there. So you will need to also remove this.
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.
filter_var_array()declaresarray|false|null, butnullis unreachable.The function has exactly two exits:
RETURN_FALSEwhen the filter id is unknown, andphp_filter_array_handler(), which establishes an array on both of its branches before doing anything else —ZVAL_DUP()of the input, which is aZ_PARAM_ARRAY, orarray_init(). The handler's remaining exits areRETURN_THROWS().The sibling
filter_input_array()is declared identically and does returnnull, deliberately, since its source superglobal may not exist:That case has no equivalent in
filter_var_array(), whose source is a requiredarrayparameter. The two signatures look symmetrical but only one of them can producenull.Verification
Swept every registered filter from
filter_list(), as the global int form and inside an options array, across six flag combinations includingFILTER_NULL_ON_FAILURE,FILTER_FORCE_ARRAYandFILTER_REQUIRE_SCALAR, against inputs chosen to make filters fail, with$add_emptyboth ways. 3024 calls on 8.5.4:array2848 times,TypeError88,ValueError88, plusfalsefor the unknown filter id.nullnever appears.Worth noting that
nullremains an ordinary element value in the returned array, which is likely where the wider union came from:That is the value type, not the return type.
Only the stub changes; the arginfo is regenerated and the edit is confined to
arginfo_filter_var_array,filter_input_arraykeepsMAY_BE_NULL.Note
This is behaviour-preserving on the engine side, but it does tighten what userland is told, and it shows up in
ReflectionFunction::getReturnType(). Whether that belongs in a minor or should wait for a major is the maintainers' call.