|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61527 ArrayIterator gives misleading notice on next() when moved to the end
Submitted: 2012-03-27 12:16 UTC Modified: 2012-07-15 05:41 UTC
From: gtisza at gmail dot com Assigned: stas
Status: Closed Package: SPL related
PHP Version: 5.3.10 OS: Debian
Private report: No CVE-ID:
 [2012-03-27 12:16 UTC] gtisza at gmail dot com
When trying to iterate the ArrayIterator of an empty ArrayObject, it throws a very misleading notice complaining about how the array was modified. In a complicated system, this will likely lead to a long wild goose chase of trying to find all the possible places where the object could have been accessed through some other iterator, when in reality the error is of a completely different nature.

Test script:
$ao = new ArrayObject(array());
$ai = $ao->getIterator();

Expected result:
$ai->next() returns null; no errors. (Or maybe a notice saying you reached the end of the array.)

Actual result:
$ai->next() returns null and throws a notice saying "ArrayIterator::next(): Array was modified outside object and internal position is no longer valid".


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-04-05 17:46 UTC] reeze dot xia at gmail dot com
Hi, gtisza:
   I have analyzed this misleading notice and found that it show misleading 
notice when manipulate empty or move the end of array. 

   I made a pull request to show more meaningful notice instead of misleading 

here it is:

will someone review it for me?

 [2012-04-05 18:12 UTC] reeze dot xia at gmail dot com
  I think "ArrayIterator gives misleading notice on manipulate empty or moved to 
end array" will be a better title for the bug description, what do you think?
 [2012-07-15 05:35 UTC]
-Summary: ArrayIterator created from empty ArrayObject gives misleading notice on next() +Summary: ArrayIterator gives misleading notice on next() when moved to the end
 [2012-07-15 05:35 UTC]
Automatic comment on behalf of stas
Log: Fixed bug #61527 (Recursive/ArrayIterator gives misleading notice when array empty or moved to the end)
 [2012-07-15 05:41 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at

 For Windows:
Thank you for the report, and for helping us make PHP better.

merged to 5.4
 [2012-07-15 05:41 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: stas
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sun Apr 20 08:02:33 2014 UTC