php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37623 offsetUnset() on foreached arrayObject item throw E_NOTICE
Submitted: 2006-05-29 09:27 UTC Modified: 2006-05-29 18:29 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: sperson at lfdj dot com Assigned: helly (profile)
Status: Not a bug Package: SPL related
PHP Version: 5.* OS: *
Private report: No CVE-ID: None
 [2006-05-29 09:27 UTC] sperson at lfdj dot com
Description:
------------
When we do a foreach on an arrayObject, and we want to unset some item from the loop a NOTICE is thrown.

Don't know if this is the intended behaviour but in case of doubt I prefer to submit.

Reproduce code:
---------------
$coll = new ArrayObject();
$coll->append(new stdClass());
foreach ($coll as $index => $item) {
	$coll->offsetUnset($index);
}

Expected result:
----------------
nothing

Actual result:
--------------
Notice: main() [function.main]: ArrayIterator::next(): Array was modified outside object and internal position is no longer valid in index.php on line 7


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-29 09:48 UTC] mike@php.net
AFAICT this is intended.
 [2006-05-29 18:29 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The notice means that foreach rewinds or moves to its end. Whatever the ArrayIterator decides.
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC