xref: /PHP-8.0/ext/spl/tests/iterator_024.phpt (revision f8d79582)
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--EXPECT--
311
322
3331
3432
35331
364
37string(13) "ArrayIterator"
38An instance of RecursiveIterator or IteratorAggregate creating it is required
39===MANUAL===
40string(22) "RecursiveArrayIterator"
411
422
4331
4432
45331
464
47