Skip to content

fix(Validation): correct required_without logic and prevent array key warnings#10328

Open
gr8man wants to merge 3 commits into
codeigniter4:developfrom
gr8man:fix/required-without-logic
Open

fix(Validation): correct required_without logic and prevent array key warnings#10328
gr8man wants to merge 3 commits into
codeigniter4:developfrom
gr8man:fix/required-without-logic

Conversation

@gr8man

@gr8man gr8man commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Description
This PR fixes two bugs in the required_without validation rule when used with array dot notation.

  1. Early return bug: Previously, when multiple fields were provided to the required_without rule (e.g., required_without[a.*.b,a.*.c]), the foreach loop inside the method would prematurely return true as soon as it found the first present field. This caused the rule to completely ignore any subsequent fields in the array, leading to incorrect validation passes even if the subsequent fields were missing. This has been fixed by continuing the loop to check all declared fields.
  2. Undefined array key warning: When resolving dot notation, if the intermediate dot_array_search returned null or a non-array, trying to access [$fieldKey] directly resulted in an Undefined array key warning. Added the null coalescing operator (?? null) and a safe check with empty() to prevent PHP warnings when the array key is not set.

Added testRequireWithoutMultipleWithAsterisk to ValidationTest.php to prove the bug was resolved.

Checklist:

  • Securely signed commits
  • Component(s) with PHPunit tests
  • Binaries, fluffs, etc. are ignored
  • Debug codes are removed
  • A descriptive pull request title
  • Code modifications have been well commented
  • Code follows the project's coding standards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant