1--TEST--
2null 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: Trying to access array offset on null 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():
44
45OUTPUT;
46
47$EXPECTED_OUTPUT_VALID_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_VALID_OFFSETS) . '$/s';
48
49const EXPECTF_OUTPUT_FLOAT_OFFSETS = <<<OUTPUT
50Read before write:
51
52Warning: Trying to access array offset on null in %s on line %d
53NULL
54Write:
55
56Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
57Read:
58
59Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
60int(5)
61Read-Write:
62
63Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
64isset():
65
66Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
67bool(true)
68empty():
69
70Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
71bool(false)
72null coalesce:
73
74Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
75int(25)
76Reference to dimension:
77
78Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
79Value of reference:
80int(25)
81Value of container dimension after write to reference (should be int(100) if successful):
82
83Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
84int(100)
85unset():
86
87Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
88Nested read:
89
90Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
91
92Warning: Undefined array key 0 in %s on line %d
93
94Warning: Trying to access array offset on null in %s on line %d
95NULL
96Nested write:
97
98Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
99
100Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
101Nested Read-Write:
102
103Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
104
105Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
106Nested isset():
107
108Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
109
110Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
111bool(true)
112Nested empty():
113
114Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
115
116Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
117bool(false)
118Nested null coalesce:
119
120Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
121
122Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
123int(30)
124Nested unset():
125
126Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
127
128Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
129
130OUTPUT;
131
132$EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTF_OUTPUT_FLOAT_OFFSETS) . '$/s';
133
134const EXPECTED_OUTPUT_INVALID_OFFSETS = <<<OUTPUT
135Read before write:
136
137Warning: Trying to access array offset on null in %s on line %d
138NULL
139Write:
140Cannot access offset of type %s on array
141Read:
142Cannot access offset of type %s on array
143Read-Write:
144Cannot access offset of type %s on array
145isset():
146Cannot access offset of type %s in isset or empty
147empty():
148Cannot access offset of type %s in isset or empty
149null coalesce:
150Cannot access offset of type %s on array
151Reference to dimension:
152Cannot access offset of type %s on array
153unset():
154Cannot unset offset of type %s on array
155Nested read:
156Cannot access offset of type %s on array
157Nested write:
158Cannot access offset of type %s on array
159Nested Read-Write:
160Cannot access offset of type %s on array
161Nested isset():
162Cannot access offset of type %s on array
163Nested empty():
164Cannot access offset of type %s on array
165Nested null coalesce:
166Cannot access offset of type %s on array
167Nested unset():
168Cannot access offset of type %s on array
169
170OUTPUT;
171
172$EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_INVALID_OFFSETS) . '$/s';
173
174const EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS = <<<OUTPUT
175Read before write:
176
177Warning: Trying to access array offset on null in %s on line 8
178NULL
179Write:
180
181Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 15
182Read:
183
184Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 22
185int(5)
186Read-Write:
187
188Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 29
189isset():
190
191Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 36
192bool(true)
193empty():
194
195Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 42
196bool(false)
197null coalesce:
198
199Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 48
200int(25)
201Reference to dimension:
202
203Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 55
204Value of reference:
205int(25)
206Value of container dimension after write to reference (should be int(100) if successful):
207
208Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 60
209int(100)
210unset():
211
212Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 67
213Nested read:
214
215Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 74
216
217Warning: Undefined array key 3 in %s on line 74
218
219Warning: Trying to access array offset on null in %s on line 74
220NULL
221Nested write:
222
223Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 81
224
225Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 81
226Nested Read-Write:
227
228Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 88
229
230Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 88
231Nested isset():
232
233Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 95
234
235Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 95
236bool(true)
237Nested empty():
238
239Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 101
240
241Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 101
242bool(false)
243Nested null coalesce:
244
245Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 107
246
247Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 107
248int(30)
249Nested unset():
250
251Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 114
252
253Warning: Resource ID#3 used as offset, casting to integer (3) in %s on line 114
254
255OUTPUT;
256
257ob_start();
258foreach ($offsets as $dimension) {
259    $container = null;
260    $error = 'null[' . zend_test_var_export($dimension) . '] has different outputs' . "\n";
261
262    include $var_dim_filename;
263    $varOutput = ob_get_contents();
264    ob_clean();
265    $varOutput = str_replace(
266        [$var_dim_filename],
267        ['%s'],
268        $varOutput
269    );
270
271    if (
272        !preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput)
273        && !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput)
274        && !preg_match($EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX, $varOutput)
275        && $varOutput !== EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS
276    ) {
277        file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_null_container_{$failuresNb}.txt", $varOutput);
278        ++$failuresNb;
279        $failures[] = $error;
280    }
281    ++$testCasesTotal;
282}
283/* Using offsets as references */
284foreach ($offsets as $offset) {
285    $dimension = &$offset;
286    $container = null;
287    $error = 'null[&' . zend_test_var_export($offset) . '] has different outputs' . "\n";
288
289    include $var_dim_filename;
290    $varOutput = ob_get_contents();
291    ob_clean();
292    $varOutput = str_replace(
293        [$var_dim_filename],
294        ['%s'],
295        $varOutput
296    );
297
298    if (
299        !preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput)
300        && !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput)
301        && !preg_match($EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX, $varOutput)
302        && $varOutput !== EXPECTED_OUTPUT_RESOURCE_STDERR_OFFSETS
303    ) {
304        file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_null_container_{$failuresNb}.txt", $varOutput);
305        ++$failuresNb;
306        $failures[] = $error;
307    }
308    ++$testCasesTotal;
309}
310ob_end_clean();
311
312echo "Executed tests\n";
313if ($failures !== []) {
314    echo "Failures:\n" . implode($failures);
315}
316
317?>
318--EXPECT--
319Executed tests
320