Edit report at https://bugs.php.net/bug.php?id=63917&edit=1
ID: 63917
Comment by: LastDragon at yandex dot ru
Reported by: LastDragon at yandex dot ru
Summary: SplObjectStorage: Iteration of all the objects is
not possible after detach()
Status: Open
Type: Bug
Package: SPL related
Operating System: all
PHP Version: 5.4.10
Block user comment: N
Private report: N
New Comment:
> Are the "Expected" and "Actual" blocks reversed on this initial report?
Yes. Sorry. Unfortunately I cannot edit this blocks :(
Previous Comments:
------------------------------------------------------------------------
[2013-01-08 21:05:06] [email protected]
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