1--TEST--
2ArrayObject containers behaviour with offsets
3--FILE--
4<?php
5
6require_once __DIR__ . DIRECTORY_SEPARATOR . 'test_offset_helpers.inc';
7
8const EXPECTED_OUTPUT_VALID_OFFSETS = <<<OUTPUT
9Read before write:
10
11Warning: Undefined array key %s in %s on line %d
12NULL
13Write:
14Read:
15int(5)
16Read-Write:
17isset():
18bool(true)
19empty():
20bool(false)
21null coalesce:
22int(25)
23Reference to dimension:
24Value of reference:
25int(25)
26Value of container dimension after write to reference (should be int(100) if successful):
27int(100)
28unset():
29Nested read:
30
31Warning: Undefined array key %s in %s on line %d
32
33Warning: Trying to access array offset on null in %s on line %d
34NULL
35Nested write:
36Nested Read-Write:
37Nested isset():
38bool(true)
39Nested empty():
40bool(false)
41Nested null coalesce:
42int(30)
43Nested unset():
44OUTPUT;
45
46$EXPECTED_OUTPUT_VALID_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_VALID_OFFSETS) . '$/s';
47
48const EXPECTF_OUTPUT_FLOAT_OFFSETS = <<<OUTPUT
49Read before write:
50
51Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
52
53Warning: Undefined array key %s in %s on line %d
54NULL
55Write:
56
57Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
58Read:
59
60Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
61int(15)
62Read-Write:
63
64Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
65isset():
66
67Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
68bool(true)
69empty():
70
71Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
72bool(false)
73null coalesce:
74
75Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
76int(35)
77Reference to dimension:
78
79Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
80Value of reference:
81int(35)
82Value of container dimension after write to reference (should be int(100) if successful):
83
84Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
85int(100)
86unset():
87
88Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
89Nested read:
90
91Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
92
93Warning: Undefined array key 0 in %s on line %d
94
95Warning: Trying to access array offset on null in %s on line %d
96NULL
97Nested write:
98
99Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
100
101Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
102Nested Read-Write:
103
104Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
105
106Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
107Nested isset():
108
109Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
110
111Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
112bool(true)
113Nested empty():
114
115Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
116
117Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
118bool(false)
119Nested null coalesce:
120
121Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
122
123Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
124int(25)
125Nested unset():
126
127Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
128
129Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
130
131OUTPUT;
132
133$EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTF_OUTPUT_FLOAT_OFFSETS) . '$/s';
134
135const EXPECTED_OUTPUT_INVALID_OFFSETS = <<<OUTPUT
136Read before write:
137Cannot access offset of type %s on ArrayObject
138Write:
139Cannot access offset of type %s on ArrayObject
140Read:
141Cannot access offset of type %s on ArrayObject
142Read-Write:
143Cannot access offset of type %s on ArrayObject
144isset():
145Cannot access offset of type %s in isset or empty
146empty():
147Cannot access offset of type %s in isset or empty
148null coalesce:
149Cannot access offset of type %s in isset or empty
150Reference to dimension:
151Cannot access offset of type %s on ArrayObject
152unset():
153Cannot unset offset of type %s on ArrayObject
154Nested read:
155Cannot access offset of type %s on ArrayObject
156Nested write:
157Cannot access offset of type %s on ArrayObject
158Nested Read-Write:
159Cannot access offset of type %s on ArrayObject
160Nested isset():
161Cannot access offset of type %s in isset or empty
162Nested empty():
163Cannot access offset of type %s in isset or empty
164Nested null coalesce:
165Cannot access offset of type %s in isset or empty
166Nested unset():
167
168Notice: Indirect modification of overloaded element of ArrayObject has no effect in %s on line %d
169Cannot unset offset of type %s on ArrayObject
170
171OUTPUT;
172
173$EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_INVALID_OFFSETS) . '$/s';
174
175const EXPECTED_OUTPUT_NULL_OFFSET = <<<OUTPUT
176Read before write:
177
178Warning: Undefined array key "" in %s on line 8
179NULL
180Write:
181Read:
182
183Warning: Undefined array key "" in %s on line 22
184NULL
185Read-Write:
186
187Warning: Undefined array key "" in %s on line 29
188isset():
189bool(false)
190empty():
191bool(true)
192null coalesce:
193string(7) "default"
194Reference to dimension:
195Value of reference:
196NULL
197Value of container dimension after write to reference (should be int(100) if successful):
198int(100)
199unset():
200Nested read:
201
202Warning: Undefined array key "" in %s on line 74
203
204Warning: Trying to access array offset on null in %s on line 74
205NULL
206Nested write:
207Nested Read-Write:
208Nested isset():
209bool(true)
210Nested empty():
211bool(false)
212Nested null coalesce:
213int(30)
214Nested unset():
215
216OUTPUT;
217
218const EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS = <<<OUTPUT
219Read before write:
220
221Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 8
222
223Warning: Undefined array key 3 in %s on line 8
224NULL
225Write:
226
227Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 15
228Read:
229
230Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 22
231int(5)
232Read-Write:
233
234Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 29
235
236Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 29
237isset():
238
239Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 36
240bool(true)
241empty():
242
243Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 42
244bool(false)
245null coalesce:
246
247Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 48
248int(25)
249Reference to dimension:
250
251Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 55
252Value of reference:
253int(25)
254Value of container dimension after write to reference (should be int(100) if successful):
255
256Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 60
257int(100)
258unset():
259
260Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 67
261Nested read:
262
263Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 74
264
265Warning: Undefined array key 3 in %s on line 74
266
267Warning: Trying to access array offset on null in %s on line 74
268NULL
269Nested write:
270
271Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 81
272
273Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 81
274Nested Read-Write:
275
276Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 88
277
278Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 88
279Nested isset():
280
281Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 95
282
283Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 95
284bool(true)
285Nested empty():
286
287Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 101
288
289Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 101
290bool(false)
291Nested null coalesce:
292
293Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 107
294
295Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 107
296int(30)
297Nested unset():
298
299Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 114
300
301Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 114
302
303OUTPUT;
304
305ob_start();
306foreach ($offsets as $dimension) {
307    $container = new ArrayObject();
308    $error = '(new ArrayObject())[' . zend_test_var_export($dimension) . '] has different outputs' . "\n";
309    ob_start();
310    var_dump($dimension);
311    $var_dump_output = ob_get_clean();
312
313    include $var_dim_filename;
314    $varOutput = ob_get_contents();
315    ob_clean();
316    $varOutput = str_replace(
317        [$var_dim_filename],
318        ['%s'],
319        $varOutput
320    );
321
322    if (
323        !preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput)
324        && !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput)
325        && !preg_match($EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX, $varOutput)
326        && $varOutput !== EXPECTED_OUTPUT_NULL_OFFSET
327        && $varOutput !== EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS
328    ) {
329        file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_ArrayObject_container_{$failuresNb}.txt", $varOutput);
330        ++$failuresNb;
331        $failures[] = $error;
332    }
333    ++$testCasesTotal;
334}
335/* Using offsets as references */
336foreach ($offsets as $offset) {
337    $dimension = &$offset;
338    $container = new ArrayObject();
339    $error = '(new ArrayObject())[&' . zend_test_var_export($dimension) . '] has different outputs' . "\n";
340    ob_start();
341    var_dump($dimension);
342    $var_dump_output = ob_get_clean();
343
344    include $var_dim_filename;
345    $varOutput = ob_get_contents();
346    ob_clean();
347    $varOutput = str_replace(
348        [$var_dim_filename],
349        ['%s'],
350        $varOutput
351    );
352
353    if (
354        !preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput)
355        && !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput)
356        && !preg_match($EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX, $varOutput)
357        && $varOutput !== EXPECTED_OUTPUT_NULL_OFFSET
358        && $varOutput !== EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS
359    ) {
360        file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_ArrayObject_container_{$failuresNb}.txt", $varOutput);
361        ++$failuresNb;
362        $failures[] = $error;
363    }
364    ++$testCasesTotal;
365}
366ob_end_clean();
367
368echo "Executed tests\n";
369if ($failures !== []) {
370    echo "Failures:\n" . implode($failures);
371}
372
373?>
374--EXPECT--
375Executed tests
376