Edit report at https://bugs.php.net/bug.php?id=63917&edit=1
ID: 63917 Updated by: le...@php.net Reported by: LastDragon at yandex dot ru Summary: SplObjectStorage: Iteration of all the objects is not possible after detach() -Status: Open +Status: Duplicate Type: Bug Package: SPL related Operating System: all PHP Version: 5.4.10 Block user comment: N Private report: N New Comment: This is duplicate of bug #65629 (https://bugs.php.net/bug.php?id=65629). Previous Comments: ------------------------------------------------------------------------ [2013-01-09 15:18:22] ashn...@php.net The following patch has been added/updated: Patch Name: bug63917.phpt Revision: 1357744702 URL: https://bugs.php.net/patch-display.php?bug=63917&patch=bug63917.phpt&revision=1357744702 ------------------------------------------------------------------------ [2013-01-09 06:05:45] LastDragon at yandex dot ru > Are the "Expected" and "Actual" blocks reversed on this initial report? Yes. Sorry. Unfortunately I cannot edit this blocks :( ------------------------------------------------------------------------ [2013-01-08 21:05:06] ashn...@php.net Are the "Expected" and "Actual" blocks reversed on this initial report? I came searching for an SplObjectStorage bug where attempting to foreach() it and detach all its members was failing to detach the final member. This bug report looks like it reports exactly that, if you switch the Expected and Actual blocks. In my case, a foreach() around one SplObjectStorage object that performs a detach() per member is finishing the foreach() loop while leaving one member still attached. I can do a second foreach() on the SplObjectStorage object, and this time it does see the remaining one member and detaches it successfully. I suspect, as this bug report seems to specifically say, that the detach() operation in the foreach() is causing an off-by-one error or is implicitly calling one of the Iterator methods in a way that throws off the foreach()'s Iterator steps. ------------------------------------------------------------------------ [2013-01-06 11:25:18] LastDragon at yandex dot ru Description: ------------ Iteration of all the objects is not possible after the detach method was called. Test script: --------------- <?php $s = new SplObjectStorage(); $s->attach(new StdClass); $s->attach(new StdClass); $s->attach(new StdClass); $s->attach(new StdClass); var_dump($s->count()); foreach ($s as $v) { var_dump($v); $s->detach($v); } var_dump($s->count()); Expected result: ---------------- int(4) object(stdClass)#2 (0) { } object(stdClass)#4 (0) { } object(stdClass)#5 (0) { } int(1) Actual result: -------------- int(4) object(stdClass)#2 (0) { } object(stdClass)#3 (0) { } object(stdClass)#4 (0) { } object(stdClass)#5 (0) { } int(0) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=63917&edit=1