fix: required_without() premature return inside foreach loop#10297
Closed
gr8man wants to merge 2 commits into
Closed
fix: required_without() premature return inside foreach loop#10297gr8man wants to merge 2 commits into
gr8man wants to merge 2 commits into
Conversation
Bug: return statements inside the foreach loop caused only the first field in the otherFields list to be checked. All subsequent fields were silently ignored. - Refactored: foreach loop no longer contains early returns; each iteration independently determines whether to return false. - Added: null coalescing for field key access - Added: explicit is_array() check before array access to prevent warnings when dot_array_search() returns null - Added: validation for missing field key on dot-path fields
4dd694a to
2cd2f69
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.
Bug
In
Rules::required_without(), theforeachloop over$otherFieldscontained early
returnstatements in the dot-path branch (lines 435, 440).This caused only the first field in a comma-separated list to be evaluated;
all subsequent fields were silently ignored.
For example,
required_without[a.*.b, a.*.c]would only checka.*.band return immediately, never inspecting
a.*.c.Fix
foreachbody so no iteration contains areturnstatement.Each field is independently evaluated, and
falseis returned only whena missing dependency is found.
?? nullcoalescing for$fieldSplitArray[1]with a validationguard against malformed dot-path fields.
is_array()check before array-key access on the resultof
dot_array_search(), preventing a PHP Warning when it returnsnull.Tests
testRequireWithoutWithMultipleAsterisk– verifies that botha.*.banda.*.dare checked when usingrequired_without[a.*.b, a.*.d].testRequireWithoutWithMultipleAsteriskLastMissing– verifies thatvalidation fails when the last dot-path field is absent.