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