Bug #61527 [Com]: ArrayIterator created from empty ArrayObject gives misleading notice on next()
| From: | reeze dot xia at gmail dot com | Date: | Thu, 05 Apr 2012 17:46:42 +0000 |
| Subject: | Bug #61527 [Com]: ArrayIterator created from empty ArrayObject gives misleading notice on next() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-169274@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=61527&edit=1
ID: 61527
Comment by: reeze dot xia at gmail dot com
Reported by: gtisza at gmail dot com
Summary: ArrayIterator created from empty ArrayObject gives
misleading notice on next()
Status: Open
Type: Bug
Package: SPL related
Operating System: Debian
PHP Version: 5.3.10
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2012-03-27 12:16:11] 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".
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=61527&edit=1