Detect FILTER_THROW_ON_FAILURE in filter_input(), filter_var_array() and filter_input_array() - #6514
Merged
Merged
Conversation
…ay()` and `filter_input_array()` The flag works with all four filter functions, but only `filter_var()` was covered. * The throw type extension, renamed to FilterFunctionsThrowTypeExtension, reports Filter\FilterFailedException for all four functions. FilterFunctionFlagsHelper locates the flags, including the per-key filter specifications of the array variants, where an integer `$options` is the filter id and carries no flags. * FilterVarRule reports the conflicting FILTER_NULL_ON_FAILURE and FILTER_THROW_ON_FAILURE for the same four functions and handles named arguments, which the rule sees unnormalized. * `filter_input()` throws on a missing input value when FILTER_THROW_ON_FAILURE is set, so its return type no longer includes null or false for it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SCH8hvECi7zaEUr1Get7sG
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_THROW_ON_FAILUREworks with all four filter functions —php_filter_call()in php-src is shared byfilter_var(),filter_input(),filter_var_array()andfilter_input_array()— but onlyfilter_var()was covered.FilterFunctionsThrowTypeExtension, reportsFilter\FilterFailedExceptionfor all four functions. The newFilterFunctionFlagsHelperlocates the flags, including the per-key filter specifications of the array variants, where an integer$optionsis the filter id and carries no flags.FilterVarRulereports the conflictingFILTER_NULL_ON_FAILUREandFILTER_THROW_ON_FAILUREfor the same four functions and handles named arguments, which a rule sees unnormalized.filter_input()throws on a missing input value whenFILTER_THROW_ON_FAILUREis set, so its return type no longer includesnull/falsefor it.The runtime behaviour was checked on PHP 8.5.5:
filter_input()throwsinput value 'foo' not found,filter_var_array()throws for a per-keyFILTER_THROW_ON_FAILURE, and the array variants raise the same "cannot use both"ValueError.User-visible effect: with
exceptions.implicitThrows: false, catchingFilter\FilterFailedExceptionaround the other three functions was reported as a dead catch. WithmissingCheckedExceptionInThrows, their callers now need the@throwstag, the same asfilter_var()callers. With the defaultimplicitThrows: truethe calls already had an implicit throw point, so the existingCatchWithUnthrownExceptionRuleTestdata passes with and without this change.AbilityToDisableImplicitThrowsTestcovers it instead and fails without the change.Split out of #6112.
🤖 Generated with Claude Code
https://claude.ai/code/session_01SCH8hvECi7zaEUr1Get7sG