Bug #55157 [Csd]: ArrayIterator::offsetUnset(); does not work correctly

From: Date: Tue, 13 Apr 2021 11:54:29 +0000
Subject: Bug #55157 [Csd]: ArrayIterator::offsetUnset(); does not work correctly
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233386@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=55157&edit=1 ID: 55157 Updated by: cmb@php.net Reported by: olav at fwt dot no Summary: ArrayIterator::offsetUnset(); does not work correctly Status: Closed Type: Bug Package: SPL related Operating System: openSUSE 11.4/Debian 5 PHP Version: Irrelevant Assigned To: cmb Block user comment: N Private report: N New Comment: Indeed, fixed as of PHP 7.0.0. Previous Comments: ------------------------------------------------------------------------ [2021-04-13 11:54:29] cmb@php.net Indeed, fixed as of PHP 7.0.0. ------------------------------------------------------------------------ [2020-06-09 09:33:21] alexinbeijing at gmail dot com Just submitted a PR to update the documentation on this issue... ------------------------------------------------------------------------ [2020-06-09 09:32:43] alexinbeijing at gmail dot com The following pull request has been associated: Patch Name: Add note on behavior of ArrayIterator::offsetUnset when used on current iteration index On GitHub: https://github.com/php/doc-en/pull/118 Patch: https://github.com/php/doc-en/pull/118.patch ------------------------------------------------------------------------ [2020-04-22 07:24:45] alexinbeijing at gmail dot com This bug is already fixed and the report should be closed. The original repro code prints keys 0, 2, 4, 6, and 8, which is expected. This is because when ::offsetUnset() deletes the current iteration key, it bumps the current iteration position to the next element. Then, when ::next() is called, it bumps the position forward again. So it results in iterating over every second element. The subsequent repro code which was stated to only leave key 1 in place actually leaves all the odd-numbered keys (1, 3, 5, 7, and 9) in place, for the same reason stated above. Just seeing if documentation for ::offsetUnset() can be updated to make this clearer... ------------------------------------------------------------------------ [2015-04-19 00:47:35] mw dot wanrooij at vodafonevast dot nl Same problem here, as mentioned earlier: "It seems that calling ArrayIterator::offsetUnset moves the internal pointer to the next element when removing the first index" Is there any progress on a fix? ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=55157 -- Edit this bug report at https://bugs.php.net/bug.php?id=55157&edit=1

« previous php.bugs (#233386) next »