xref: /PHP-7.4/ext/spl/tests/iterator_027.phpt (revision 610c7fbe)
1--TEST--
2SPL: CachingIterator::FULL_CACHE
3--FILE--
4<?php
5
6$ar = array(1, 2, array(31, 32, array(331)), 4);
7
8$it = new RecursiveArrayIterator($ar);
9$it = new RecursiveIteratorIterator($it);
10$it = new CachingIterator($it, CachingIterator::FULL_CACHE);
11
12foreach($it as $k=>$v)
13{
14	echo "$k=>$v\n";
15}
16
17echo "===CHECK===\n";
18
19for ($i = 0; $i < 4; $i++)
20{
21	if (isset($it[$i]))
22	{
23		var_dump($i, $it[$i]);
24	}
25}
26
27$it[2] = 'foo';
28$it[3] = 'bar';
29$it['baz'] = '25';
30
31var_dump($it[2]);
32var_dump($it[3]);
33var_dump($it['baz']);
34
35unset($it[0]);
36unset($it[2]);
37unset($it['baz']);
38
39var_dump(isset($it[0])); // unset
40var_dump(isset($it[1])); // still present
41var_dump(isset($it[2])); // unset
42var_dump(isset($it[3])); // still present
43var_dump(isset($it['baz']));
44
45echo "===REWIND===\n";
46
47$it->rewind(); // cleans and reads first element
48var_dump(isset($it[0])); // pre-fetched
49var_dump(isset($it[1])); // deleted
50var_dump(isset($it[2])); // unset
51var_dump(isset($it[3])); // deleted
52
53?>
54===DONE===
55<?php exit(0); ?>
56--EXPECT--
570=>1
581=>2
590=>31
601=>32
610=>331
623=>4
63===CHECK===
64int(0)
65int(331)
66int(1)
67int(32)
68int(3)
69int(4)
70string(3) "foo"
71string(3) "bar"
72string(2) "25"
73bool(false)
74bool(true)
75bool(false)
76bool(true)
77bool(false)
78===REWIND===
79bool(true)
80bool(false)
81bool(false)
82bool(false)
83===DONE===
84