Bug #68278 [Com]: RecursiveIteratorIterator fails when passed an IteratorAggregate
| From: | chuck at manchuck dot com | Date: | Tue, 21 Oct 2014 19:48:06 +0000 |
| Subject: | Bug #68278 [Com]: RecursiveIteratorIterator fails when passed an IteratorAggregate | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-188236@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=68278&edit=1
ID: 68278
Comment by: chuck at manchuck dot com
Reported by: chuck at manchuck dot com
Summary: RecursiveIteratorIterator fails when passed an
IteratorAggregate
Status: Not a bug
Type: Bug
Package: SPL related
Operating System: windows/*nix
PHP Version: 5.5.18
Block user comment: N
Private report: N
New Comment:
ArrayObject is an IteratorAggregate and this bug still presents itself:
$iterator = new RecursiveIteratorIterator(new \ArrayObject([]));
Previous Comments:
------------------------------------------------------------------------
[2014-10-21 19:21:41] requinix@php.net
RecursiveIteratorIterator is an iterator over other recursive iterators. As such it needs to be
given either (a) a RecursiveIterator or (b) an IteratorAggregate that produces a RecursiveIterator.
ArrayIterator is not recursive, thus the error. Use RecursiveArrayIterator instead.
http://3v4l.org/Ia7qL
------------------------------------------------------------------------
[2014-10-21 15:00:08] chuck at manchuck dot com
This will also cause the same error:
$iterator = new RecursiveIteratorIterator(new \ArrayObject([]));
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'An instance
of RecursiveIterator or IteratorAggregate creating it is required' in
/var/www/sando/bin/iteratorBug.php on line 2
InvalidArgumentException: An instance of RecursiveIterator or IteratorAggregate creating it is
required in /var/www/sando/bin/iteratorBug.php on line 2
ArrayObject does implement IteratorAggregate:
$ php -r 'var_dump(class_implements("\ArrayObject"));'
array(5) {
'IteratorAggregate' =>
string(17) "IteratorAggregate"
'Traversable' =>
string(11) "Traversable"
'ArrayAccess' =>
string(11) "ArrayAccess"
'Serializable' =>
string(12) "Serializable"
'Countable' =>
string(9) "Countable"
}
------------------------------------------------------------------------
[2014-10-21 14:54:51] chuck at manchuck dot com
Description:
------------
When RecursiveIteratorIterator is given an IteratorAggregate, a fatal exception is thrown.
Test script:
---------------
class IteratorBug implements IteratorAggregate
{
public function getIterator()
{
return new ArrayIterator([]);
}
}
$iterator = new RecursiveIteratorIterator(new IteratorBug());
Expected result:
----------------
a RecursiveIteratorIterator is created
Actual result:
--------------
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'An instance
of RecursiveIterator or IteratorAggregate creating it is required' in
/var/www/sando/bin/iteratorBug.php on line 11
InvalidArgumentException: An instance of RecursiveIterator or IteratorAggregate creating it is
required in /var/www/sando/bin/iteratorBug.php on line 11
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68278&edit=1