1--TEST--
2String 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: Uninitialized string offset %d in %s on line %d
12string(0) ""
13Write:
14Read:
15string(1) "5"
16Read-Write:
17Cannot use assign-op operators with string offsets
18isset():
19bool(true)
20empty():
21bool(false)
22null coalesce:
23string(1) "5"
24Reference to dimension:
25Cannot create references %s string offsets
26unset():
27Cannot unset string offsets
28Nested read:
29
30Warning: Uninitialized string offset %d in %s on line %d
31string(0) ""
32Nested write:
33Cannot use string offset as an array
34Nested Read-Write:
35Cannot use string offset as an array
36Nested isset():
37bool(false)
38Nested empty():
39bool(true)
40Nested null coalesce:
41string(7) "default"
42Nested unset():
43Cannot use string offset as an array
44
45OUTPUT;
46
47$EXPECTED_OUTPUT_VALID_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_VALID_OFFSETS) . '$/s';
48
49const EXPECTED_OUTPUT_VALID_OFFSETS_OUT_OF_RANGE = <<<OUTPUT
50Read before write:
51
52Warning: Uninitialized string offset %i in %s on line %d
53string(0) ""
54Write:
55
56Warning: Illegal string offset %i in %s on line %d
57Read:
58
59Warning: Uninitialized string offset %i in %s on line %d
60string(0) ""
61Read-Write:
62Cannot use assign-op operators with string offsets
63isset():
64bool(false)
65empty():
66bool(true)
67null coalesce:
68string(7) "default"
69Reference to dimension:
70Cannot create references %s string offsets
71unset():
72Cannot unset string offsets
73Nested read:
74
75Warning: Uninitialized string offset %i in %s on line %d
76
77Warning: Uninitialized string offset %i in %s on line %d
78string(0) ""
79Nested write:
80Cannot use string offset as an array
81Nested Read-Write:
82Cannot use string offset as an array
83Nested isset():
84bool(false)
85Nested empty():
86bool(true)
87Nested null coalesce:
88string(7) "default"
89Nested unset():
90Cannot use string offset as an array
91
92OUTPUT;
93
94$EXPECTED_OUTPUT_VALID_OFFSETS_OUT_OF_RANGE_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_VALID_OFFSETS_OUT_OF_RANGE) . '$/s';
95
96const EXPECTED_OUTPUT_STRING_CAST_OFFSETS = <<<OUTPUT
97Read before write:
98
99Warning: String offset cast occurred in %s on line %d
100
101Warning: Uninitialized string offset %d in %s on line %d
102string(0) ""
103Write:
104
105Warning: String offset cast occurred in %s on line %d
106Read:
107
108Warning: String offset cast occurred in %s on line %d
109string(1) "5"
110Read-Write:
111
112Warning: String offset cast occurred in %s on line %d
113Cannot use assign-op operators with string offsets
114isset():
115bool(true)
116empty():
117bool(false)
118null coalesce:
119string(1) "5"
120Reference to dimension:
121
122Warning: String offset cast occurred in %s on line %d
123Cannot create references %s string offsets
124unset():
125Cannot unset string offsets
126Nested read:
127
128Warning: String offset cast occurred in %s on line %d
129
130Warning: String offset cast occurred in %s on line %d
131
132Warning: Uninitialized string offset %d in %s on line %d
133string(0) ""
134Nested write:
135
136Warning: String offset cast occurred in %s on line %d
137Cannot use string offset as an array
138Nested Read-Write:
139
140Warning: String offset cast occurred in %s on line %d
141Cannot use string offset as an array
142Nested isset():
143bool(false)
144Nested empty():
145bool(true)
146Nested null coalesce:
147string(7) "default"
148Nested unset():
149
150Warning: String offset cast occurred in %s on line %d
151Cannot use string offset as an array
152
153OUTPUT;
154
155$EXPECTED_OUTPUT_STRING_CAST_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_STRING_CAST_OFFSETS) . '$/s';
156
157const EXPECTED_OUTPUT_STRING_CAST_OFFSETS_TO_0 = <<<OUTPUT
158Read before write:
159
160Warning: String offset cast occurred in %s on line %d
161
162Warning: Uninitialized string offset 0 in %s on line %d
163string(0) ""
164Write:
165
166Warning: String offset cast occurred in %s on line %d
167Read:
168
169Warning: String offset cast occurred in %s on line %d
170string(1) "5"
171Read-Write:
172
173Warning: String offset cast occurred in %s on line %d
174Cannot use assign-op operators with string offsets
175isset():
176bool(true)
177empty():
178bool(false)
179null coalesce:
180string(1) "5"
181Reference to dimension:
182
183Warning: String offset cast occurred in %s on line %d
184Cannot create references %s string offsets
185unset():
186Cannot unset string offsets
187Nested read:
188
189Warning: String offset cast occurred in %s on line %d
190
191Warning: String offset cast occurred in %s on line %d
192string(1) "5"
193Nested write:
194
195Warning: String offset cast occurred in %s on line %d
196Cannot use string offset as an array
197Nested Read-Write:
198
199Warning: String offset cast occurred in %s on line %d
200Cannot use string offset as an array
201Nested isset():
202bool(true)
203Nested empty():
204bool(false)
205Nested null coalesce:
206string(1) "5"
207Nested unset():
208
209Warning: String offset cast occurred in %s on line %d
210Cannot use string offset as an array
211
212OUTPUT;
213
214$EXPECTED_OUTPUT_STRING_CAST_OFFSETS_TO_0_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_STRING_CAST_OFFSETS_TO_0) . '$/s';
215
216const EXPECTED_OUTPUT_STRING_CAST_OFFSETS_OUT_OF_RANGE = <<<OUTPUT
217Read before write:
218
219Warning: String offset cast occurred in %s on line %d
220
221Warning: Uninitialized string offset %i in %s on line %d
222string(0) ""
223Write:
224
225Warning: String offset cast occurred in %s on line %d
226
227Warning: Illegal string offset %i in %s on line %d
228Read:
229
230Warning: String offset cast occurred in %s on line %d
231
232Warning: Uninitialized string offset %i in %s on line %d
233string(0) ""
234Read-Write:
235
236Warning: String offset cast occurred in %s on line %d
237Cannot use assign-op operators with string offsets
238isset():
239bool(false)
240empty():
241bool(true)
242null coalesce:
243string(7) "default"
244Reference to dimension:
245
246Warning: String offset cast occurred in %s on line %d
247Cannot create references %s string offsets
248unset():
249Cannot unset string offsets
250Nested read:
251
252Warning: String offset cast occurred in %s on line %d
253
254Warning: Uninitialized string offset %i in %s on line %d
255
256Warning: String offset cast occurred in %s on line %d
257
258Warning: Uninitialized string offset %i in %s on line %d
259string(0) ""
260Nested write:
261
262Warning: String offset cast occurred in %s on line %d
263Cannot use string offset as an array
264Nested Read-Write:
265
266Warning: String offset cast occurred in %s on line %d
267Cannot use string offset as an array
268Nested isset():
269bool(false)
270Nested empty():
271bool(true)
272Nested null coalesce:
273string(7) "default"
274Nested unset():
275
276Warning: String offset cast occurred in %s on line %d
277Cannot use string offset as an array
278
279OUTPUT;
280
281$EXPECTED_OUTPUT_STRING_CAST_OFFSETS_OUT_OF_RANGE_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_STRING_CAST_OFFSETS_OUT_OF_RANGE) . '$/s';
282
283const EXPECTF_OUTPUT_FLOAT_OFFSETS_OUT_OF_RANGE = <<<OUTPUT
284Read before write:
285
286Warning: String offset cast occurred in %s on line %d
287
288Warning: Uninitialized string offset %i in %s on line %d
289string(0) ""
290Write:
291
292Warning: String offset cast occurred in %s on line %d
293
294Warning: Illegal string offset %i in %s on line %d
295Read:
296
297Warning: String offset cast occurred in %s on line %d
298
299Warning: Uninitialized string offset %i in %s on line %d
300string(0) ""
301Read-Write:
302
303Warning: String offset cast occurred in %s on line %d
304Cannot use assign-op operators with string offsets
305isset():
306
307Deprecated: Implicit conversion from float %f to int loses precision in %s on line %d
308bool(false)
309empty():
310
311Deprecated: Implicit conversion from float %f to int loses precision in %s on line %d
312bool(true)
313null coalesce:
314string(7) "default"
315Reference to dimension:
316
317Warning: String offset cast occurred in %s on line %d
318Cannot create references %s string offsets
319unset():
320Cannot unset string offsets
321Nested read:
322
323Warning: String offset cast occurred in %s on line %d
324
325Warning: Uninitialized string offset %i in %s on line %d
326
327Warning: String offset cast occurred in %s on line %d
328
329Warning: Uninitialized string offset %i in %s on line %d
330string(0) ""
331Nested write:
332
333Warning: String offset cast occurred in %s on line %d
334Cannot use string offset as an array
335Nested Read-Write:
336
337Warning: String offset cast occurred in %s on line %d
338Cannot use string offset as an array
339Nested isset():
340bool(false)
341Nested empty():
342bool(true)
343Nested null coalesce:
344string(7) "default"
345Nested unset():
346
347Warning: String offset cast occurred in %s on line %d
348Cannot use string offset as an array
349
350OUTPUT;
351
352$EXPECTF_OUTPUT_FLOAT_OFFSETS_OUT_OF_RANGE_REGEX = '/^' . expectf_to_regex(EXPECTF_OUTPUT_FLOAT_OFFSETS_OUT_OF_RANGE) . '$/s';
353
354const EXPECTED_OUTPUT_FLOAT_INF_NAN_OFFSETS = <<<OUTPUT
355Read before write:
356
357Warning: String offset cast occurred in %s on line %d
358
359Warning: Uninitialized string offset %d in %s on line %d
360string(0) ""
361Write:
362
363Warning: String offset cast occurred in %s on line %d
364Read:
365
366Warning: String offset cast occurred in %s on line %d
367string(1) "5"
368Read-Write:
369
370Warning: String offset cast occurred in %s on line %d
371Cannot use assign-op operators with string offsets
372isset():
373
374Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
375bool(true)
376empty():
377
378Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
379bool(false)
380null coalesce:
381string(1) "5"
382Reference to dimension:
383
384Warning: String offset cast occurred in %s on line %d
385Cannot create references %s string offsets
386unset():
387Cannot unset string offsets
388Nested read:
389
390Warning: String offset cast occurred in %s on line %d
391
392Warning: String offset cast occurred in %s on line %d
393string(1) "5"
394Nested write:
395
396Warning: String offset cast occurred in %s on line %d
397Cannot use string offset as an array
398Nested Read-Write:
399
400Warning: String offset cast occurred in %s on line %d
401Cannot use string offset as an array
402Nested isset():
403
404Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
405bool(true)
406Nested empty():
407
408Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d
409bool(false)
410Nested null coalesce:
411string(1) "5"
412Nested unset():
413
414Warning: String offset cast occurred in %s on line %d
415Cannot use string offset as an array
416
417OUTPUT;
418
419$EXPECTED_OUTPUT_FLOAT_INF_NAN_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_FLOAT_INF_NAN_OFFSETS) . '$/s';
420
421const EXPECTED_OUTPUT_INVALID_OFFSETS = <<<OUTPUT
422Read before write:
423Cannot access offset of type %s on string
424Write:
425Cannot access offset of type %s on string
426Read:
427Cannot access offset of type %s on string
428Read-Write:
429Cannot access offset of type %s on string
430isset():
431bool(false)
432empty():
433bool(true)
434null coalesce:
435Cannot access offset of type %s on string
436Reference to dimension:
437Cannot access offset of type %s on string
438unset():
439Cannot unset string offsets
440Nested read:
441Cannot access offset of type %s on string
442Nested write:
443Cannot access offset of type %s on string
444Nested Read-Write:
445Cannot access offset of type %s on string
446Nested isset():
447Cannot access offset of type %s on string
448Nested empty():
449Cannot access offset of type %s on string
450Nested null coalesce:
451Cannot access offset of type %s on string
452Nested unset():
453Cannot unset string offsets
454
455OUTPUT;
456
457$EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_INVALID_OFFSETS) . '$/s';
458
459const EXPECTED_OUTPUT_INVALID_OFFSETS_AS_STRINGS = <<<OUTPUT
460Read before write:
461Cannot access offset of type string on string
462Write:
463Cannot access offset of type string on string
464Read:
465Cannot access offset of type string on string
466Read-Write:
467Cannot access offset of type string on string
468isset():
469bool(false)
470empty():
471bool(true)
472null coalesce:
473string(7) "default"
474Reference to dimension:
475Cannot access offset of type string on string
476unset():
477Cannot unset string offsets
478Nested read:
479Cannot access offset of type string on string
480Nested write:
481Cannot access offset of type string on string
482Nested Read-Write:
483Cannot access offset of type string on string
484Nested isset():
485bool(false)
486Nested empty():
487bool(true)
488Nested null coalesce:
489string(7) "default"
490Nested unset():
491Cannot unset string offsets
492
493OUTPUT;
494
495const EXPECTED_OUTPUT_INVALID_OFFSETS_AS_LEADING_NUMERIC_STRINGS = <<<OUTPUT
496Read before write:
497
498Warning: Illegal string offset %s in %s on line %d
499
500Warning: Uninitialized string offset %d in %s on line %d
501string(0) ""
502Write:
503
504Warning: Illegal string offset %s in %s on line %d
505Read:
506
507Warning: Illegal string offset %s in %s on line %d
508string(1) "5"
509Read-Write:
510
511Warning: Illegal string offset %s in %s on line %d
512Cannot use assign-op operators with string offsets
513isset():
514bool(false)
515empty():
516bool(true)
517null coalesce:
518
519Warning: Illegal string offset %s in %s on line %d
520string(1) "5"
521Reference to dimension:
522
523Warning: Illegal string offset %s in %s on line %d
524Cannot create references %s string offsets
525unset():
526Cannot unset string offsets
527Nested read:
528
529Warning: Illegal string offset %s in %s on line %d
530
531Warning: Illegal string offset %s in %s on line %d
532
533Warning: Uninitialized string offset %d in %s on line %d
534string(0) ""
535Nested write:
536
537Warning: Illegal string offset %s in %s on line %d
538Cannot use string offset as an array
539Nested Read-Write:
540
541Warning: Illegal string offset %s in %s on line %d
542Cannot use string offset as an array
543Nested isset():
544
545Warning: Illegal string offset %s in %s on line %d
546bool(false)
547Nested empty():
548
549Warning: Illegal string offset %s in %s on line %d
550bool(true)
551Nested null coalesce:
552
553Warning: Illegal string offset %s in %s on line %d
554
555Warning: Illegal string offset %s in %s on line %d
556string(7) "default"
557Nested unset():
558Cannot use string offset as an array
559
560OUTPUT;
561
562$EXPECTED_OUTPUT_INVALID_OFFSETS_AS_LEADING_NUMERIC_STRINGS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_INVALID_OFFSETS_AS_LEADING_NUMERIC_STRINGS) . '$/s';
563
564const EXPECTED_OUTPUT_INVALID_OFFSETS_AS_LEADING_NUMERIC_STRINGS_TO_0 = <<<OUTPUT
565Read before write:
566
567Warning: Illegal string offset %s in %s on line %d
568
569Warning: Uninitialized string offset 0 in %s on line %d
570string(0) ""
571Write:
572
573Warning: Illegal string offset %s in %s on line %d
574Read:
575
576Warning: Illegal string offset %s in %s on line %d
577string(1) "5"
578Read-Write:
579
580Warning: Illegal string offset %s in %s on line %d
581Cannot use assign-op operators with string offsets
582isset():
583bool(false)
584empty():
585bool(true)
586null coalesce:
587
588Warning: Illegal string offset %s in %s on line %d
589string(1) "5"
590Reference to dimension:
591
592Warning: Illegal string offset %s in %s on line %d
593Cannot create references %s string offsets
594unset():
595Cannot unset string offsets
596Nested read:
597
598Warning: Illegal string offset %s in %s on line %d
599
600Warning: Illegal string offset %s in %s on line %d
601string(1) "5"
602Nested write:
603
604Warning: Illegal string offset %s in %s on line %d
605Cannot use string offset as an array
606Nested Read-Write:
607
608Warning: Illegal string offset %s in %s on line %d
609Cannot use string offset as an array
610Nested isset():
611
612Warning: Illegal string offset %s in %s on line %d
613bool(false)
614Nested empty():
615
616Warning: Illegal string offset %s in %s on line %d
617bool(true)
618Nested null coalesce:
619
620Warning: Illegal string offset %s in %s on line %d
621
622Warning: Illegal string offset %s in %s on line %d
623string(1) "5"
624Nested unset():
625Cannot use string offset as an array
626
627OUTPUT;
628
629$EXPECTED_OUTPUT_INVALID_OFFSETS_AS_LEADING_NUMERIC_STRINGS_TO_0_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_INVALID_OFFSETS_AS_LEADING_NUMERIC_STRINGS_TO_0) . '$/s';
630
631ob_start();
632foreach ($offsets as $dimension) {
633    $container = '';
634    $error = '""[' . zend_test_var_export($dimension) . '] has different outputs' . "\n";
635
636    include $var_dim_filename;
637    $varOutput = ob_get_contents();
638    ob_clean();
639    $varOutput = str_replace(
640        [$var_dim_filename],
641        ['%s'],
642        $varOutput
643    );
644
645    if (
646        !preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput)
647        && !preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_OUT_OF_RANGE_REGEX, $varOutput)
648        && !preg_match($EXPECTED_OUTPUT_STRING_CAST_OFFSETS_REGEX, $varOutput)
649        && !preg_match($EXPECTED_OUTPUT_STRING_CAST_OFFSETS_TO_0_REGEX, $varOutput)
650        && !preg_match($EXPECTED_OUTPUT_STRING_CAST_OFFSETS_OUT_OF_RANGE_REGEX, $varOutput)
651        && !preg_match($EXPECTF_OUTPUT_FLOAT_OFFSETS_OUT_OF_RANGE_REGEX, $varOutput)
652        && !preg_match($EXPECTED_OUTPUT_FLOAT_INF_NAN_OFFSETS_REGEX, $varOutput)
653        && !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput)
654        && $varOutput !== EXPECTED_OUTPUT_INVALID_OFFSETS_AS_STRINGS
655        && !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_AS_LEADING_NUMERIC_STRINGS_REGEX, $varOutput)
656        && !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_AS_LEADING_NUMERIC_STRINGS_TO_0_REGEX, $varOutput)
657    ) {
658        file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_string_container_{$failuresNb}.txt", $varOutput);
659        ++$failuresNb;
660        $failures[] = $error;
661    }
662    ++$testCasesTotal;
663}
664/* Using offsets as references */
665foreach ($offsets as $offset) {
666    $dimension = &$offset;
667    $container = '';
668    $error = '""[&' . zend_test_var_export($offset) . '] has different outputs' . "\n";
669
670    include $var_dim_filename;
671    $varOutput = ob_get_contents();
672    ob_clean();
673    $varOutput = str_replace(
674        [$var_dim_filename],
675        ['%s'],
676        $varOutput
677    );
678
679    if (
680        !preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput)
681        && !preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_OUT_OF_RANGE_REGEX, $varOutput)
682        && !preg_match($EXPECTED_OUTPUT_STRING_CAST_OFFSETS_REGEX, $varOutput)
683        && !preg_match($EXPECTED_OUTPUT_STRING_CAST_OFFSETS_TO_0_REGEX, $varOutput)
684        && !preg_match($EXPECTED_OUTPUT_STRING_CAST_OFFSETS_OUT_OF_RANGE_REGEX, $varOutput)
685        && !preg_match($EXPECTF_OUTPUT_FLOAT_OFFSETS_OUT_OF_RANGE_REGEX, $varOutput)
686        && !preg_match($EXPECTED_OUTPUT_FLOAT_INF_NAN_OFFSETS_REGEX, $varOutput)
687        && !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput)
688        && $varOutput !== EXPECTED_OUTPUT_INVALID_OFFSETS_AS_STRINGS
689        && !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_AS_LEADING_NUMERIC_STRINGS_REGEX, $varOutput)
690        && !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_AS_LEADING_NUMERIC_STRINGS_TO_0_REGEX, $varOutput)
691    ) {
692        file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_string_container_{$failuresNb}.txt", $varOutput);
693        ++$failuresNb;
694        $failures[] = $error;
695    }
696    ++$testCasesTotal;
697}
698ob_end_clean();
699
700echo "Executed tests\n";
701if ($failures !== []) {
702    echo "Failures:\n" . implode($failures);
703}
704
705?>
706--EXPECT--
707Executed tests
708