xref: /PHP-7.2/ext/spl/tests/array_010.phpt (revision 610c7fbe)
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===DONE===
65<?php exit(0); ?>
66--EXPECTF--
67array(4) {
68  [0]=>
69  string(3) "1st"
70  [1]=>
71  int(1)
72  [2]=>
73  string(3) "3rd"
74  ["4th"]=>
75  int(4)
76}
77===EMPTY===
78bool(false)
79bool(false)
80bool(false)
81bool(false)
82bool(true)
83bool(true)
84===isset===
85bool(true)
86bool(true)
87bool(true)
88bool(true)
89bool(false)
90bool(false)
91===offsetGet===
92string(3) "1st"
93int(1)
94string(3) "3rd"
95int(4)
96
97Notice: Undefined index: 5th in %sarray_010.php on line %d
98NULL
99
100Notice: Undefined offset: 6 in %sarray_010.php on line %d
101NULL
102===offsetSet===
103WRITE 1
104string(9) "Changed 1"
105WRITE 2
106string(11) "Changed 4th"
107WRITE 3
108string(9) "Added 5th"
109WRITE 4
110string(7) "Added 6"
111string(3) "1st"
112string(3) "3rd"
113string(9) "changed 6"
114string(9) "changed 6"
115===unset===
116array(6) {
117  [0]=>
118  string(3) "1st"
119  [1]=>
120  string(9) "Changed 1"
121  [2]=>
122  string(3) "3rd"
123  ["4th"]=>
124  string(11) "Changed 4th"
125  ["5th"]=>
126  string(9) "Added 5th"
127  [6]=>
128  string(9) "changed 6"
129}
130
131Notice: Undefined offset: 7 in %sarray_010.php on line %d
132
133Notice: Undefined index: 8th in %sarray_010.php on line %d
134array(4) {
135  [0]=>
136  string(3) "1st"
137  [1]=>
138  string(9) "Changed 1"
139  ["5th"]=>
140  string(9) "Added 5th"
141  [6]=>
142  string(9) "changed 6"
143}
144===DONE===
145