fix(database): use currentRow instead of customResultObject in getRowObject and add null fallback#10257
fix(database): use currentRow instead of customResultObject in getRowObject and add null fallback#10257gr8man wants to merge 2 commits into
Conversation
… add null fallback
|
Hi there, gr8man! 👋 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 🤖 |
BaseResult::getRowObject() and BaseResult::getRowArray()
michalsn
left a comment
There was a problem hiding this comment.
Neither test exercises the newly added ?? null fallback. When an invalid requested index such as 999 is passed, currentRow remains 0, so the methods return the first row exactly as they did before this change.
Please add tests that set $result->currentRow to an invalid index before calling getRowArray() and getRowObject(). Since currentRow is public, this is the scenario the fallback handles.
Also, if invalid stored cursors are now expected to return null, please apply the same handling consistently to getCustomRowObject() and getPreviousRow(), which can still emit "Undefined array key" warnings.
Fix two bugs in
BaseResult::getRowObject()andBaseResult::getRowArray():Wrong property comparison in
getRowObject()— The method compared$nagainst$this->customResultObject(an array) instead of$this->currentRow(an int). Since$n !== []is alwaystruefor any integer, the condition always entered the branch, making theisset()check the only effective guard. This caused inconsistentcurrentRowtracking betweengetRowArray()andgetRowObject().Missing null guard on row access — Both
getRowArray()andgetRowObject()accessed$result[$this->currentRow]without checking if the key exists, potentially triggering anUndefined array keywarning when the storedcurrentRowpoints to a non-existent index.Checklist: