Bug #65629 [Com]: SplObjectsStorage::detach() rewinds internal pointer
Edit report at https://bugs.php.net/bug.php?id=65629&edit=1
ID: 65629
Comment by: artter178 at gmail dot com
Reported by: alan dot bem at gmail dot com
Summary: SplObjectsStorage::detach() rewinds internal pointer
Status: Assigned
Type: Bug
Package: SPL related
PHP Version: Irrelevant
Assigned To: levim
Block user comment: N
Private report: N
New Comment:
Dear php team, can you fix this behaviour?
Previous Comments:
------------------------------------------------------------------------
[2018-08-19 16:49:10] cmb@php.net
> It's behaviour should be more similar to ArrayObject, it's less
> confusing that way.
Is it less confusing? Consider:
<?php
$items = new ArrayObject(range(1, 10));
foreach ($items as $key => $val) {
unset($items[$key]);
}
print_r($items->getArrayCopy());
prints:
Array
(
[1] => 2
[3] => 4
[5] => 6
[7] => 8
[9] => 10
)
------------------------------------------------------------------------
[2015-07-20 10:08:56] bas at dmt-software dot nl
SplObjectsStorage::attach() does change the pointer too.
These operations should not change the internal pointer at all.
It's behaviour should be more similar to ArrayObject, it's less confusing that way.
------------------------------------------------------------------------
[2013-09-21 23:02:47] levim@php.net
Bug #63917 is a duplicate of this one (has a phpt uploaded -- might be useful).
------------------------------------------------------------------------
[2013-09-21 22:58:59] levim@php.net
Related To: Bug #63917
------------------------------------------------------------------------
[2013-09-12 22:49:38] levim@php.net
Regardless of whether this is a bug, in general modifying a structure during
iteration has undefined behavior. I will look a bit into this and see what might
be done.
------------------------------------------------------------------------
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=65629
--
Edit this bug report at https://bugs.php.net/bug.php?id=65629&edit=1
Thread (7 messages)