xref: /PHP-8.2/ext/spl/tests/array_015.phpt (revision f8d79582)
1--TEST--
2SPL: ArrayIterator::next() with internal arrays
3--FILE--
4<?php
5
6$ar = new ArrayObject();
7
8$ar[0] = 1;
9$ar[1] = 2;
10$ar[2] = 3;
11$ar[3] = 4;
12$ar[4] = 5;
13
14var_dump($ar);
15
16$it = $ar->getIterator();
17
18$ar->offsetUnset($it->key());
19$it->next();
20
21var_dump($it->current());
22var_dump($ar);
23
24foreach($it as $k => $v)
25{
26    $ar->offsetUnset($k+1);
27    echo "$k=>$v\n";
28}
29
30var_dump($ar);
31
32foreach($it as $k => $v)
33{
34    $ar->offsetUnset($k);
35    echo "$k=>$v\n";
36}
37
38var_dump($ar);
39
40?>
41--EXPECTF--
42object(ArrayObject)#%d (1) {
43  %s"storage"%s"ArrayObject":private]=>
44  array(5) {
45    [0]=>
46    int(1)
47    [1]=>
48    int(2)
49    [2]=>
50    int(3)
51    [3]=>
52    int(4)
53    [4]=>
54    int(5)
55  }
56}
57int(3)
58object(ArrayObject)#%d (1) {
59  %s"storage"%s"ArrayObject":private]=>
60  array(4) {
61    [1]=>
62    int(2)
63    [2]=>
64    int(3)
65    [3]=>
66    int(4)
67    [4]=>
68    int(5)
69  }
70}
711=>2
723=>4
73object(ArrayObject)#%d (1) {
74  %s"storage"%s"ArrayObject":private]=>
75  array(2) {
76    [1]=>
77    int(2)
78    [3]=>
79    int(4)
80  }
81}
821=>2
83object(ArrayObject)#%d (1) {
84  %s"storage"%s"ArrayObject":private]=>
85  array(1) {
86    [3]=>
87    int(4)
88  }
89}
90