Skip to content

feat: allow array_group_by to group object rows#10226

Open
syawqy wants to merge 1 commit into
codeigniter4:developfrom
syawqy:fix-array-group-by-objects
Open

feat: allow array_group_by to group object rows#10226
syawqy wants to merge 1 commit into
codeigniter4:developfrom
syawqy:fix-array-group-by-objects

Conversation

@syawqy
Copy link
Copy Markdown

@syawqy syawqy commented May 21, 2026

Description

Fixes #10225.

This PR updates array_group_by() so it can group rows that are objects, such as rows returned by json_decode() or object-based result sets.

Previously, the internal grouping helper required each row to be an array and used dot_array_search(), which also only accepts arrays. That caused a type error when grouping an array of stdClass objects.

The change keeps the public helper API unchanged and adds internal dot-path lookup support for array/object rows. Grouped rows are preserved as their original type, so object rows remain objects in the result.

Regression tests were added for:

  • Grouping stdClass rows by a direct property.
  • Grouping object rows by a nested dot path.

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

@syawqy syawqy force-pushed the fix-array-group-by-objects branch from f6c68af to da3a0d9 Compare May 21, 2026 13:45
@mergeable
Copy link
Copy Markdown

mergeable Bot commented May 21, 2026

Hi there, syawqy! 👋

Thank you for sending this PR!

We expect the following in all Pull Requests (PRs).

Important

We expect all code changes or bug-fixes to be accompanied by one or more tests added to our test suite to prove the code works.

If pull requests do not comply with the above, they will likely be closed. Since we are a team of volunteers, we don't have any more time to work
on the framework than you do. Please make it as painless for your contributions to be included as possible.

See https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/pull_request.md

Sincerely, the mergeable bot 🤖

@patel-vansh
Copy link
Copy Markdown
Contributor

Thanks for the PR. I think object handling in array helper's dot syntax is not being implemented anywhere in the ArrayHelper. I don't know if its indented or not, but if this PR gets merged, we would require follow-up PRs for other methods as well.

@michalsn michalsn changed the title fix: allow array_group_by to group object rows feat: allow array_group_by to group object rows May 21, 2026
@michalsn michalsn added the wrong branch PRs sent to wrong branch label May 21, 2026
Copy link
Copy Markdown
Member

@michalsn michalsn left a comment

Choose a reason for hiding this comment

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

Thank you for sending a PR. Unfortunately, it cannot be merged in its current form.

Since this would be an enhancement rather than a bug fix, it should target the 4.8 branch. Also, as mentioned above, support for arrays of objects should be considered consistently across the other array methods/helpers that currently support only arrays of arrays.

@michalsn michalsn added docs needed Pull requests needing documentation write-ups and/or revisions. needs rework Changes requested by reviewer that are still pending labels May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs needed Pull requests needing documentation write-ups and/or revisions. needs rework Changes requested by reviewer that are still pending wrong branch PRs sent to wrong branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

array_group_by helper function does not accept array of objects

3 participants