forked from php/php-src
/
temporary_cleaning_013.phpt
311 lines (276 loc) · 9.23 KB
/
temporary_cleaning_013.phpt
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
--TEST--
Exceptions thrown in operand cleaning must cause leak of return value
--FILE--
<?php
try {
var_dump(new class {
function __toString() { return "a"; }
function __destruct() { throw new Exception; }
} . "foo");
} catch (Exception $e) { print "caught Exception 1\n"; }
try {
var_dump([0] + [new class {
function __destruct() { throw new Exception; }
}]);
} catch (Exception $e) { print "caught Exception 2\n"; }
try {
$foo = [0];
var_dump($foo += [new class {
function __destruct() { throw new Exception; }
}]);
} catch (Exception $e) { print "caught Exception 3\n"; }
try {
$foo = (object)["foo" => [0]];
var_dump($foo->foo += [new class {
function __destruct() { throw new Exception; }
}]);
} catch (Exception $e) { print "caught Exception 4\n"; }
try {
$foo = new class {
function __get($x) { return [0]; }
function __set($x, $y) {}
};
var_dump($foo->foo += [new class {
function __destruct() { throw new Exception; }
}]);
} catch (Exception $e) { print "caught Exception 5\n"; }
try {
$foo = new class {
public $bar = [0];
function &__get($x) { return $this->bar; }
};
var_dump($foo->foo += [new class {
function __destruct() { throw new Exception; }
}]);
} catch (Exception $e) { print "caught Exception 6\n"; }
try {
$foo = new class implements ArrayAccess {
function offsetGet($x) { return [0]; }
function offsetSet($x, $y) {}
function offsetExists($x) { return true; }
function offsetUnset($x) {}
};
var_dump($foo[0] += [new class {
function __destruct() { throw new Exception; }
}]);
} catch (Exception $e) { print "caught Exception 7\n"; }
try {
$foo = new class implements ArrayAccess {
public $foo = [0];
function &offsetGet($x) { return $this->foo; }
function offsetSet($x, $y) {}
function offsetExists($x) { return true; }
function offsetUnset($x) {}
};
var_dump($foo[0] += [new class {
function __destruct() { throw new Exception; }
}]);
} catch (Exception $e) { print "caught Exception 8\n"; }
try {
var_dump((function() { return new class {
function __construct() { $this->foo = new stdClass; }
function __destruct() { throw new Exception; }
}; })()->foo++);
} catch (Exception $e) { print "caught Exception 9\n"; }
try {
var_dump((function() { return new class {
function __get($x) { return new stdClass; }
function __set($x, $y) {}
function __destruct() { throw new Exception; }
}; })()->foo++);
} catch (Exception $e) { print "caught Exception 10\n"; }
try {
var_dump((function() { return new class {
function __construct() { $this->bar = new stdClass; }
function &__get($x) { return $this->bar; }
function __destruct() { throw new Exception; }
}; })()->foo++);
} catch (Exception $e) { print "caught Exception 11\n"; }
try {
var_dump(++(function() { return new class {
function __construct() { $this->foo = new stdClass; }
function __destruct() { throw new Exception; }
}; })()->foo);
} catch (Exception $e) { print "caught Exception 12\n"; }
try {
var_dump(++(function() { return new class {
function __get($x) { return new stdClass; }
function __set($x, $y) {}
function __destruct() { throw new Exception; }
}; })()->foo);
} catch (Exception $e) { print "caught Exception 13\n"; }
try {
var_dump(++(function() { return new class {
function __construct() { $this->bar = new stdClass; }
function &__get($x) { return $this->bar; }
function __destruct() { throw new Exception; }
}; })()->foo);
} catch (Exception $e) { print "caught Exception 14\n"; }
try {
var_dump((function() { return new class implements ArrayAccess {
function offsetGet($x) { return [new stdClass]; }
function offsetSet($x, $y) {}
function offsetExists($x) { return true; }
function offsetUnset($x) {}
function __destruct() { throw new Exception; }
}; })()[0]++);
} catch (Exception $e) { print "caught Exception 15\n"; }
try {
var_dump(++(function() { return new class implements ArrayAccess {
function offsetGet($x) { return [new stdClass]; }
function offsetSet($x, $y) {}
function offsetExists($x) { return true; }
function offsetUnset($x) {}
function __destruct() { throw new Exception; }
}; })()[0]);
} catch (Exception $e) { print "caught Exception 16\n"; }
try {
var_dump((new class {
function __construct() { $this->foo = new stdClass; }
function __destruct() { throw new Exception; }
})->foo);
} catch (Exception $e) { print "caught Exception 17\n"; }
try {
var_dump((new class {
function __get($x) { return new stdClass; }
function __set($x, $y) {}
function __destruct() { throw new Exception; }
})->foo);
} catch (Exception $e) { print "caught Exception 18\n"; }
try {
var_dump((new class implements ArrayAccess {
function offsetGet($x) { return [new stdClass]; }
function offsetSet($x, $y) {}
function offsetExists($x) { return true; }
function offsetUnset($x) {}
function __destruct() { throw new Exception; }
})[0]);
} catch (Exception $e) { print "caught Exception 19\n"; }
try {
var_dump(isset((new class {
function __construct() { $this->foo = new stdClass; }
function __destruct() { throw new Exception; }
})->foo->bar));
} catch (Exception $e) { print "caught Exception 20\n"; }
try {
var_dump(isset((new class {
function __get($x) { return new stdClass; }
function __set($x, $y) {}
function __destruct() { throw new Exception; }
})->foo->bar));
} catch (Exception $e) { print "caught Exception 21\n"; }
try {
var_dump(isset((new class implements ArrayAccess {
function offsetGet($x) { return [new stdClass]; }
function offsetSet($x, $y) {}
function offsetExists($x) { return true; }
function offsetUnset($x) {}
function __destruct() { throw new Exception; }
})[0]->bar));
} catch (Exception $e) { print "caught Exception 22\n"; }
try {
$foo = new class {
function __destruct() { throw new Exception; }
};
var_dump($foo = new stdClass);
} catch (Exception $e) { print "caught Exception 23\n"; }
try {
$foo = [new class {
function __destruct() { throw new Exception; }
}];
var_dump($foo[0] = new stdClass);
} catch (Exception $e) { print "caught Exception 24\n"; }
try {
$foo = (object) ["foo" => new class {
function __destruct() { throw new Exception; }
}];
var_dump($foo->foo = new stdClass);
} catch (Exception $e) { print "caught Exception 25\n"; }
try {
$foo = new class {
function __get($x) {}
function __set($x, $y) { throw new Exception; }
};
var_dump($foo->foo = new stdClass);
} catch (Exception $e) { print "caught Exception 26\n"; }
try {
$foo = new class implements ArrayAccess {
function offsetGet($x) {}
function offsetSet($x, $y) { throw new Exception; }
function offsetExists($x) { return true; }
function offsetUnset($x) {}
};
var_dump($foo[0] = new stdClass);
} catch (Exception $e) { print "caught Exception 27\n"; }
try {
$foo = new class {
function __destruct() { throw new Exception; }
};
$bar = new stdClass;
var_dump($foo = &$bar);
} catch (Exception $e) { print "caught Exception 28\n"; }
try {
$f = function() {
return new class {
function __toString() { return "a"; }
function __destruct() { throw new Exception; }
};
};
var_dump("{$f()}foo");
} catch (Exception $e) { print "caught Exception 29\n"; }
try {
$f = function() {
return new class {
function __toString() { return "a"; }
function __destruct() { throw new Exception; }
};
};
var_dump("bar{$f()}foo");
} catch (Exception $e) { print "caught Exception 30\n"; }
try {
var_dump((string) new class {
function __toString() { $x = "Z"; return ++$x; }
function __destruct() { throw new Exception; }
});
} catch (Exception $e) { print "caught Exception 31\n"; }
try {
var_dump(clone (new class {
function __clone() { throw new Exception; }
}));
} catch (Exception $e) { print "caught Exception 32\n"; }
?>
--EXPECTF--
caught Exception 1
caught Exception 2
caught Exception 3
caught Exception 4
caught Exception 5
caught Exception 6
caught Exception 7
caught Exception 8
caught Exception 9
caught Exception 10
caught Exception 11
caught Exception 12
caught Exception 13
caught Exception 14
Notice: Indirect modification of overloaded element of ArrayAccess@anonymous has no effect in %s on line %d
caught Exception 15
Notice: Indirect modification of overloaded element of ArrayAccess@anonymous has no effect in %s on line %d
caught Exception 16
caught Exception 17
caught Exception 18
caught Exception 19
caught Exception 20
caught Exception 21
caught Exception 22
caught Exception 23
caught Exception 24
caught Exception 25
caught Exception 26
caught Exception 27
caught Exception 28
caught Exception 29
caught Exception 30
caught Exception 31
caught Exception 32