xref: /PHP-8.1/ext/spl/tests/array_010.phpt (revision 71fb8356)
1--TEST--
2SPL: ArrayIterator implements ArrayAccess
3--FILE--
4<?php
5
6$obj = new ArrayObject(array('1st', 1, 2=>'3rd', '4th'=>4));
7
8var_dump($obj->getArrayCopy());
9
10echo "===EMPTY===\n";
11var_dump(empty($obj[0]));
12var_dump(empty($obj[1]));
13var_dump(empty($obj[2]));
14var_dump(empty($obj['4th']));
15var_dump(empty($obj['5th']));
16var_dump(empty($obj[6]));
17
18echo "===isset===\n";
19var_dump(isset($obj[0]));
20var_dump(isset($obj[1]));
21var_dump(isset($obj[2]));
22var_dump(isset($obj['4th']));
23var_dump(isset($obj['5th']));
24var_dump(isset($obj[6]));
25
26echo "===offsetGet===\n";
27var_dump($obj[0]);
28var_dump($obj[1]);
29var_dump($obj[2]);
30var_dump($obj['4th']);
31var_dump($obj['5th']);
32var_dump($obj[6]);
33
34echo "===offsetSet===\n";
35echo "WRITE 1\n";
36$obj[1] = 'Changed 1';
37var_dump($obj[1]);
38echo "WRITE 2\n";
39$obj['4th'] = 'Changed 4th';
40var_dump($obj['4th']);
41echo "WRITE 3\n";
42$obj['5th'] = 'Added 5th';
43var_dump($obj['5th']);
44echo "WRITE 4\n";
45$obj[6] = 'Added 6';
46var_dump($obj[6]);
47
48var_dump($obj[0]);
49var_dump($obj[2]);
50
51$x = $obj[6] = 'changed 6';
52var_dump($obj[6]);
53var_dump($x);
54
55echo "===unset===\n";
56var_dump($obj->getArrayCopy());
57unset($obj[2]);
58unset($obj['4th']);
59unset($obj[7]);
60unset($obj['8th']);
61var_dump($obj->getArrayCopy());
62
63?>
64--EXPECTF--
65array(4) {
66  [0]=>
67  string(3) "1st"
68  [1]=>
69  int(1)
70  [2]=>
71  string(3) "3rd"
72  ["4th"]=>
73  int(4)
74}
75===EMPTY===
76bool(false)
77bool(false)
78bool(false)
79bool(false)
80bool(true)
81bool(true)
82===isset===
83bool(true)
84bool(true)
85bool(true)
86bool(true)
87bool(false)
88bool(false)
89===offsetGet===
90string(3) "1st"
91int(1)
92string(3) "3rd"
93int(4)
94
95Warning: Undefined array key "5th" in %s on line %d
96NULL
97
98Warning: Undefined array key 6 in %s on line %d
99NULL
100===offsetSet===
101WRITE 1
102string(9) "Changed 1"
103WRITE 2
104string(11) "Changed 4th"
105WRITE 3
106string(9) "Added 5th"
107WRITE 4
108string(7) "Added 6"
109string(3) "1st"
110string(3) "3rd"
111string(9) "changed 6"
112string(9) "changed 6"
113===unset===
114array(6) {
115  [0]=>
116  string(3) "1st"
117  [1]=>
118  string(9) "Changed 1"
119  [2]=>
120  string(3) "3rd"
121  ["4th"]=>
122  string(11) "Changed 4th"
123  ["5th"]=>
124  string(9) "Added 5th"
125  [6]=>
126  string(9) "changed 6"
127}
128array(4) {
129  [0]=>
130  string(3) "1st"
131  [1]=>
132  string(9) "Changed 1"
133  ["5th"]=>
134  string(9) "Added 5th"
135  [6]=>
136  string(9) "changed 6"
137}
138