php.net |  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 (profile)
Status: Closed Package: SPL related
PHP Version: 5.3.10 OS: Debian
Private report: No CVE-ID: None
 [2012-03-27 12:16 UTC] gtisza at gmail dot com
Description:
------------
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:
---------------
error_reporting(E_ALL);
$ao = new ArrayObject(array());
$ai = $ao->getIterator();
$ai->next();

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".

Patches

Pull Requests

History

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 
one.

here it is: https://github.com/php/php-src/pull/38

will someone review it for me?

Thanks.
 [2012-04-05 18:12 UTC] reeze dot xia at gmail dot com
BTW: 
  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] stas@php.net
-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] stas@php.net
Automatic comment on behalf of stas
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a5d45bae85bd75f0d57dfaf1d1c1b2b014e7949f
Log: Fixed bug #61527 (Recursive/ArrayIterator gives misleading notice when array empty or moved to the end)
 [2012-07-15 05:41 UTC] stas@php.net
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
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.

merged to 5.4
 [2012-07-15 05:41 UTC] stas@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: stas
 [2014-10-07 23:23 UTC] stas@php.net
Automatic comment on behalf of stas
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=a5d45bae85bd75f0d57dfaf1d1c1b2b014e7949f
Log: Fixed bug #61527 (Recursive/ArrayIterator gives misleading notice when array empty or moved to the end)
 [2014-10-07 23:34 UTC] stas@php.net
Automatic comment on behalf of stas
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=a5d45bae85bd75f0d57dfaf1d1c1b2b014e7949f
Log: Fixed bug #61527 (Recursive/ArrayIterator gives misleading notice when array empty or moved to the end)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 08:01:29 2024 UTC