|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-10-21 14:54 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 17:00:01 2025 UTC |
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" }Ok thanks for clearing that up. I see where what you are getting at. This worked just fine: class IteratorBug implements IteratorAggregate { public function getIterator() { return new RecursiveArrayIterator(['foo' => [1,2,3], 'bar' => [1,2,3]]); } } $iterator = new RecursiveIteratorIterator(new IteratorBug());