xref: /PHP-7.1/ext/spl/tests/iterator_024.phpt (revision 610c7fbe)
1--TEST--
2SPL: RecursiveIteratorIterator with custom iterator class
3--FILE--
4<?php
5
6$ar = array(1, 2, array(31, 32, array(331)), 4);
7
8foreach(new RecursiveIteratorIterator(new ArrayObject($ar, 0, "RecursiveArrayIterator")) as $v) echo "$v\n";
9
10$it = new ArrayObject($ar);
11var_dump($it->getIteratorClass());
12
13try
14{
15	foreach(new RecursiveIteratorIterator(new ArrayObject($ar)) as $v) echo "$v\n";
16}
17catch (InvalidArgumentException $e)
18{
19	echo $e->getMessage() . "\n";
20}
21
22echo "===MANUAL===\n";
23
24$it->setIteratorClass("RecursiveArrayIterator");
25var_dump($it->getIteratorClass());
26foreach(new RecursiveIteratorIterator($it) as $v) echo "$v\n";
27
28
29?>
30===DONE===
31<?php exit(0); ?>
32--EXPECT--
331
342
3531
3632
37331
384
39string(13) "ArrayIterator"
40An instance of RecursiveIterator or IteratorAggregate creating it is required
41===MANUAL===
42string(22) "RecursiveArrayIterator"
431
442
4531
4632
47331
484
49===DONE===
50