Skip to content

Comments

feat: add new dot-path array helpers#9990

Open
michalsn wants to merge 5 commits intocodeigniter4:4.8from
michalsn:feat/array-helper-extended
Open

feat: add new dot-path array helpers#9990
michalsn wants to merge 5 commits intocodeigniter4:4.8from
michalsn:feat/array-helper-extended

Conversation

@michalsn
Copy link
Member

Description
This PR:

  • Adds five new dot-syntax helper functions: dot_array_has(), dot_array_set(), dot_array_unset(), dot_array_only(), and dot_array_except(), each backed by a corresponding ArrayHelper static method.
  • Renames ArrayHelper::dotKeyExists() to dotHas() and updates all callers, including Validation/Rules.php and Validation/StrictRules/Rules.php. This is a safe change since ArrayHelper is marked as @internal.
  • Adds a fast path in ArrayHelper::convertToArray() that uses explode() for the common case (no escaped dots), avoiding PCRE engine overhead.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@michalsn michalsn added enhancement PRs that improve existing functionalities 4.8 PRs that target the `4.8` branch. labels Feb 22, 2026
Comment on lines +62 to +63
explode('.', $trimmed),
static fn ($s): bool => $s !== '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For micro-optimization, how about using the first-class callable strlen(...) instead of a closure to filter out empty strings while safely keeping '0'?

Suggested change
explode('.', $trimmed),
static fn ($s): bool => $s !== '',
explode('.', $trimmed),
strlen(...),

if ($index === '*') {
$result = [];

continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the array becomes completely empty here, wouldn’t using break instead of continue be more efficient to avoid processing any remaining keys?

Suggested change
continue;
break;

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

Labels

4.8 PRs that target the `4.8` branch. enhancement PRs that improve existing functionalities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants