1--TEST--
2ZE2 ArrayAccess
3--FILE--
4<?php
5class ObjectOne implements ArrayAccess {
6
7	public $a = array('1st', 1, 2=>'3rd', '4th'=>4);
8
9	function offsetExists($index) {
10		echo __METHOD__ . "($index)\n";
11		return array_key_exists($index, $this->a);
12	}
13	function offsetGet($index) {
14		echo __METHOD__ . "($index)\n";
15		return $this->a[$index];
16	}
17	function offsetSet($index, $newval) {
18		echo __METHOD__ . "($index,$newval)\n";
19		return $this->a[$index] = $newval;
20	}
21	function offsetUnset($index) {
22		echo __METHOD__ . "($index)\n";
23		unset($this->a[$index]);
24	}
25}
26
27$obj = new ObjectOne;
28
29var_dump($obj->a);
30
31echo "===EMPTY===\n";
32var_dump(empty($obj[0]));
33var_dump(empty($obj[1]));
34var_dump(empty($obj[2]));
35var_dump(empty($obj['4th']));
36var_dump(empty($obj['5th']));
37var_dump(empty($obj[6]));
38
39echo "===isset===\n";
40var_dump(isset($obj[0]));
41var_dump(isset($obj[1]));
42var_dump(isset($obj[2]));
43var_dump(isset($obj['4th']));
44var_dump(isset($obj['5th']));
45var_dump(isset($obj[6]));
46
47echo "===offsetGet===\n";
48var_dump($obj[0]);
49var_dump($obj[1]);
50var_dump($obj[2]);
51var_dump($obj['4th']);
52var_dump($obj['5th']);
53var_dump($obj[6]);
54
55echo "===offsetSet===\n";
56echo "WRITE 1\n";
57$obj[1] = 'Changed 1';
58var_dump($obj[1]);
59echo "WRITE 2\n";
60$obj['4th'] = 'Changed 4th';
61var_dump($obj['4th']);
62echo "WRITE 3\n";
63$obj['5th'] = 'Added 5th';
64var_dump($obj['5th']);
65echo "WRITE 4\n";
66$obj[6] = 'Added 6';
67var_dump($obj[6]);
68
69var_dump($obj[0]);
70var_dump($obj[2]);
71
72$x = $obj[6] = 'changed 6';
73var_dump($obj[6]);
74var_dump($x);
75
76echo "===unset===\n";
77var_dump($obj->a);
78unset($obj[2]);
79unset($obj['4th']);
80unset($obj[7]);
81unset($obj['8th']);
82var_dump($obj->a);
83
84?>
85===DONE===
86--EXPECTF--
87array(4) {
88  [0]=>
89  string(3) "1st"
90  [1]=>
91  int(1)
92  [2]=>
93  string(3) "3rd"
94  ["4th"]=>
95  int(4)
96}
97===EMPTY===
98ObjectOne::offsetExists(0)
99ObjectOne::offsetGet(0)
100bool(false)
101ObjectOne::offsetExists(1)
102ObjectOne::offsetGet(1)
103bool(false)
104ObjectOne::offsetExists(2)
105ObjectOne::offsetGet(2)
106bool(false)
107ObjectOne::offsetExists(4th)
108ObjectOne::offsetGet(4th)
109bool(false)
110ObjectOne::offsetExists(5th)
111bool(true)
112ObjectOne::offsetExists(6)
113bool(true)
114===isset===
115ObjectOne::offsetExists(0)
116bool(true)
117ObjectOne::offsetExists(1)
118bool(true)
119ObjectOne::offsetExists(2)
120bool(true)
121ObjectOne::offsetExists(4th)
122bool(true)
123ObjectOne::offsetExists(5th)
124bool(false)
125ObjectOne::offsetExists(6)
126bool(false)
127===offsetGet===
128ObjectOne::offsetGet(0)
129string(3) "1st"
130ObjectOne::offsetGet(1)
131int(1)
132ObjectOne::offsetGet(2)
133string(3) "3rd"
134ObjectOne::offsetGet(4th)
135int(4)
136ObjectOne::offsetGet(5th)
137
138Notice: Undefined index: 5th in %sarray_access_001.php on line %d
139NULL
140ObjectOne::offsetGet(6)
141
142Notice: Undefined offset: 6 in %sarray_access_001.php on line %d
143NULL
144===offsetSet===
145WRITE 1
146ObjectOne::offsetSet(1,Changed 1)
147ObjectOne::offsetGet(1)
148string(9) "Changed 1"
149WRITE 2
150ObjectOne::offsetSet(4th,Changed 4th)
151ObjectOne::offsetGet(4th)
152string(11) "Changed 4th"
153WRITE 3
154ObjectOne::offsetSet(5th,Added 5th)
155ObjectOne::offsetGet(5th)
156string(9) "Added 5th"
157WRITE 4
158ObjectOne::offsetSet(6,Added 6)
159ObjectOne::offsetGet(6)
160string(7) "Added 6"
161ObjectOne::offsetGet(0)
162string(3) "1st"
163ObjectOne::offsetGet(2)
164string(3) "3rd"
165ObjectOne::offsetSet(6,changed 6)
166ObjectOne::offsetGet(6)
167string(9) "changed 6"
168string(9) "changed 6"
169===unset===
170array(6) {
171  [0]=>
172  string(3) "1st"
173  [1]=>
174  string(9) "Changed 1"
175  [2]=>
176  string(3) "3rd"
177  ["4th"]=>
178  string(11) "Changed 4th"
179  ["5th"]=>
180  string(9) "Added 5th"
181  [6]=>
182  string(9) "changed 6"
183}
184ObjectOne::offsetUnset(2)
185ObjectOne::offsetUnset(4th)
186ObjectOne::offsetUnset(7)
187ObjectOne::offsetUnset(8th)
188array(4) {
189  [0]=>
190  string(3) "1st"
191  [1]=>
192  string(9) "Changed 1"
193  ["5th"]=>
194  string(9) "Added 5th"
195  [6]=>
196  string(9) "changed 6"
197}
198===DONE===
199