-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix iterator position resetting #13188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Previously, when an array was converted from packed to hashed, iterators would not be correctly reset to 0. Similarly, removing the last element from an array would decrease nNumUsed but not actually fix the iterator position, causing the element to be skipped in the next iteration. Some code was also removed that skips over IS_UNDEF elements for nInternalPointer and iterator positions. This is unnecessary, as this already happens during iteration. Closes phpGH-13178
The changes to zend_hash.c are fine, but you need to add extra support to php_splice() directly as that function really splices into the middle of the target array by doing a copy of it. (Also: why does php_splice unconditionally do a copy instead of like ... just in case the replacement array is bigger than the $length arg? .. Right, because it resets numerical keys, for reasons.) |
@bwoebi php_slice is adjusted accordingly. Tbh the existing behavior is somewhat dubious though. I would expect the newly appended elements to be seen, not skipped. |
Since phpGH-13188 we're no longer immediately updating iterator positions when deleting array elements. zend_hash_rehash() needs to adapt accordingly by bumping nInternalPosition for IS_UNDEF elements. This is already the case for array iterators. Fixes phpGH-19280
Since phpGH-13188 we're no longer immediately updating iterator positions when deleting array elements. zend_hash_rehash() needs to adapt accordingly by bumping nInternalPosition for IS_UNDEF elements. This is already the case for array iterators. Fixes phpGH-19280
Since phpGH-13188 we're no longer immediately updating iterator positions when deleting array elements. zend_hash_rehash() needs to adapt accordingly by adjusting nInternalPosition for IS_UNDEF elements. This is already the case for array iterators. Fixes phpGH-19280
Previously, when an array was converted from packed to hashed, iterators would not be correctly reset to 0. Similarly, removing the last element from an array would decrease nNumUsed but not actually fix the iterator position, causing the element to be skipped in the next iteration.
Some code was also removed that skips over IS_UNDEF elements for nInternalPointer and iterator positions. This is unnecessary, as this already happens during iteration.
Closes GH-13178