feat: allow array_group_by to group object rows#10226
Conversation
f6c68af to
da3a0d9
Compare
|
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 See https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/pull_request.md Sincerely, the mergeable bot 🤖 |
|
Thanks for the PR. I think object handling in array helper's dot syntax is not being implemented anywhere in the |
michalsn
left a comment
There was a problem hiding this comment.
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.
Description
Fixes #10225.
This PR updates
array_group_by()so it can group rows that are objects, such as rows returned byjson_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 ofstdClassobjects.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:
stdClassrows by a direct property.Checklist: