xref: /PHP-8.3/ext/spl/tests/iterator_027.phpt (revision f8d79582)
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--EXPECT--
550=>1
561=>2
570=>31
581=>32
590=>331
603=>4
61===CHECK===
62int(0)
63int(331)
64int(1)
65int(32)
66int(3)
67int(4)
68string(3) "foo"
69string(3) "bar"
70string(2) "25"
71bool(false)
72bool(true)
73bool(false)
74bool(true)
75bool(false)
76===REWIND===
77bool(true)
78bool(false)
79bool(false)
80bool(false)
81