1--TEST--
2array 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 array
138Write:
139Cannot access offset of type %s on array
140Read:
141Cannot access offset of type %s on array
142Read-Write:
143Cannot access offset of type %s on array
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 on array
150Reference to dimension:
151Cannot access offset of type %s on array
152unset():
153Cannot unset offset of type %s on array
154Nested read:
155Cannot access offset of type %s on array
156Nested write:
157Cannot access offset of type %s on array
158Nested Read-Write:
159Cannot access offset of type %s on array
160Nested isset():
161Cannot access offset of type %s on array
162Nested empty():
163Cannot access offset of type %s on array
164Nested null coalesce:
165Cannot access offset of type %s on array
166Nested unset():
167Cannot access offset of type %s on array
168
169OUTPUT;
170
171$EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_INVALID_OFFSETS) . '$/s';
172
173const EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS = <<<OUTPUT
174Read before write:
175
176Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 8
177
178Warning: Undefined array key 3 in %s on line 8
179NULL
180Write:
181
182Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 15
183Read:
184
185Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 22
186int(5)
187Read-Write:
188
189Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 29
190isset():
191
192Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 36
193bool(true)
194empty():
195
196Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 42
197bool(false)
198null coalesce:
199
200Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 48
201int(25)
202Reference to dimension:
203
204Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 55
205Value of reference:
206int(25)
207Value of container dimension after write to reference (should be int(100) if successful):
208
209Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 60
210int(100)
211unset():
212
213Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 67
214Nested read:
215
216Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 74
217
218Warning: Undefined array key 3 in %s on line 74
219
220Warning: Trying to access array offset on null in %s on line 74
221NULL
222Nested write:
223
224Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 81
225
226Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 81
227Nested Read-Write:
228
229Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 88
230
231Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 88
232Nested isset():
233
234Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 95
235
236Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 95
237bool(true)
238Nested empty():
239
240Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 101
241
242Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 101
243bool(false)
244Nested null coalesce:
245
246Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 107
247
248Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 107
249int(30)
250Nested unset():
251
252Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 114
253
254Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 114
255
256OUTPUT;
257
258ob_start();
259foreach ($offsets as $dimension) {
260    $container = [];
261    $error = '[][' . zend_test_var_export($dimension) . '] has different outputs' . "\n";
262
263    include $var_dim_filename;
264    $varOutput = ob_get_contents();
265    ob_clean();
266    $varOutput = str_replace(
267        [$var_dim_filename],
268        ['%s'],
269        $varOutput
270    );
271
272    if (
273        !preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput)
274        && !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput)
275        && !preg_match($EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX, $varOutput)
276        && $varOutput !== EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS
277    ) {
278        file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_array_container_{$failuresNb}.txt", $varOutput);
279        ++$failuresNb;
280        $failures[] = $error;
281    }
282    ++$testCasesTotal;
283}
284/* Using offsets as references */
285foreach ($offsets as $offset) {
286    $dimension = &$offset;
287    $container = [];
288    $error = '[][&' . zend_test_var_export($dimension) . '] has different outputs' . "\n";
289
290    include $var_dim_filename;
291    $varOutput = ob_get_contents();
292    ob_clean();
293    $varOutput = str_replace(
294        [$var_dim_filename],
295        ['%s'],
296        $varOutput
297    );
298
299    if (
300        !preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput)
301        && !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput)
302        && !preg_match($EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX, $varOutput)
303        && $varOutput !== EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS
304    ) {
305        file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_array_container_{$failuresNb}.txt", $varOutput);
306        ++$failuresNb;
307        $failures[] = $error;
308    }
309    ++$testCasesTotal;
310}
311ob_end_clean();
312
313echo "Executed tests\n";
314if ($failures !== []) {
315    echo "Failures:\n" . implode($failures);
316}
317
318?>
319--EXPECT--
320Executed tests
321