ext/filter: apply options.default only when the filter fails - #164
Closed
iliaal wants to merge 1 commit into
Closed
Conversation
iliaal
force-pushed
the
filter-bool-default-and-parse-str-string
branch
from
July 16, 2026 11:26
1ceaf87 to
fb3cad9
Compare
php_zval_filter() decided whether to apply options.default by inspecting the
filtered value for IS_FALSE, so a successful FILTER_VALIDATE_BOOL result of
false was replaced by the default. FILTER_THROW_ON_FAILURE already keys off
the handler's return code, so the two disagreed: filter_var("0",
FILTER_VALIDATE_BOOL, FILTER_THROW_ON_FAILURE) does not throw, while the same
input with a default returns the default.
Have RETURN_VALIDATION_FAILED report FAILURE for every validation failure and
key options.default off that, so both features share one notion of failure.
iliaal
force-pushed
the
filter-bool-default-and-parse-str-string
branch
from
July 16, 2026 12:21
fb3cad9 to
c6bbe00
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.
php_zval_filter()decides whether to apply options.default by inspecting the filtered value for IS_FALSE, so a successfulFILTER_VALIDATE_BOOLresult of false gets replaced by the default.FILTER_THROW_ON_FAILUREalready keys off the handler's return code, so the two features disagree about what counts as a failure:This makes
RETURN_VALIDATION_FAILEDreport FAILURE for every validation failure and keys options.default off that, so both features share one notion of failure. Net -5 lines. After the change '0' is a success for both and 'maybe' is a failure for both.BC break, so it targets master and carries an UPGRADING entry. Callers who want a valid false and a failure to stay distinct without a default still use
FILTER_NULL_ON_FAILURE.Open question before this goes upstream: it repurposes the handler return value added in 0b326dc. The comment in filter_private.h said FAILURE meant validation failed and an exception should be thrown; this widens it to validation failed, leaving the throw decision in
php_zval_filter(). That is DanielEScherzer's design call as the FILTER_THROW_ON_FAILURE RFC author.