|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63917 SplObjectStorage: Iteration of all the objects is not possible after detach()
Submitted: 2013-01-06 11:25 UTC Modified: 2013-09-21 22:58 UTC
Avg. Score:4.3 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:1 (33.3%)
From: LastDragon at yandex dot ru Assigned:
Status: Duplicate Package: SPL related
PHP Version: 5.4.10 OS: all
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
38 + 27 = ?
Subscribe to this entry?

 [2013-01-06 11:25 UTC] LastDragon at yandex dot ru
Iteration of all the objects is not possible after the detach method was called.

Test script:
$s = new SplObjectStorage();

$s->attach(new StdClass);
$s->attach(new StdClass);
$s->attach(new StdClass);
$s->attach(new StdClass);


foreach ($s as $v) {


Expected result:
object(stdClass)#2 (0) {
object(stdClass)#4 (0) {
object(stdClass)#5 (0) {

Actual result:
object(stdClass)#2 (0) {
object(stdClass)#3 (0) {
object(stdClass)#4 (0) {
object(stdClass)#5 (0) {


bug63917.phpt (last revision 2013-01-09 15:18 UTC by

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-08 21:05 UTC]
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-09 06:05 UTC] 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-09 15:18 UTC]
The following patch has been added/updated:

Patch Name: bug63917.phpt
Revision:   1357744702
 [2013-09-21 22:58 UTC]
-Status: Open +Status: Duplicate
 [2013-09-21 22:58 UTC]
This is duplicate of bug #65629 (
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Dec 02 20:03:34 2021 UTC