1--TEST--
2Invalid containers with offsets
3--FILE--
4<?php
5
6require_once __DIR__ . DIRECTORY_SEPARATOR . 'test_offset_helpers.inc';
7
8$containers = [
9    //false,
10    true,
11    4,
12    5.5,
13    STDERR,
14    //new stdClass(),
15];
16
17ob_start();
18foreach ($containers as $container) {
19    $containerStr = get_zend_debug_type($container);
20    $EXPECTED_OUTPUT = <<<OUTPUT
21Read before write:
22
23Warning: Trying to access array offset on $containerStr in %s on line 8
24NULL
25Write:
26Cannot use a scalar value as an array
27Read:
28
29Warning: Trying to access array offset on $containerStr in %s on line 22
30NULL
31Read-Write:
32Cannot use a scalar value as an array
33isset():
34bool(false)
35empty():
36bool(true)
37null coalesce:
38string(7) "default"
39Reference to dimension:
40Cannot use a scalar value as an array
41unset():
42Cannot unset offset in a non-array variable
43Nested read:
44
45Warning: Trying to access array offset on $containerStr in %s on line 74
46
47Warning: Trying to access array offset on null in %s on line 74
48NULL
49Nested write:
50Cannot use a scalar value as an array
51Nested Read-Write:
52Cannot use a scalar value as an array
53Nested isset():
54bool(false)
55Nested empty():
56bool(true)
57Nested null coalesce:
58string(7) "default"
59Nested unset():
60Cannot unset offset in a non-array variable
61
62OUTPUT;
63
64    foreach ($offsets as $dimension) {
65        $error = $containerStr . '[' . zend_test_var_export($dimension) . '] has different outputs' . "\n";
66
67        include $var_dim_filename;
68        $varOutput = ob_get_contents();
69        ob_clean();
70        $varOutput = str_replace(
71            [$var_dim_filename],
72            ['%s'],
73            $varOutput
74        );
75
76        if ($EXPECTED_OUTPUT !== $varOutput) {
77            file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_invalid_container_{$failuresNb}.txt", $varOutput);
78            ++$failuresNb;
79            $failures[] = $error;
80        }
81        ++$testCasesTotal;
82    }
83    /* Using offsets as references */
84    foreach ($offsets as $offset) {
85        $dimension = &$offset;
86        $error = $containerStr . '[&' . zend_test_var_export($dimension) . '] has different outputs' . "\n";
87
88        include $var_dim_filename;
89        $varOutput = ob_get_contents();
90        ob_clean();
91        $varOutput = str_replace(
92            [$var_dim_filename],
93            ['%s'],
94            $varOutput
95        );
96
97        if ($EXPECTED_OUTPUT !== $varOutput) {
98            file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_invalid_container_{$failuresNb}.txt", $varOutput);
99            ++$failuresNb;
100            $failures[] = $error;
101        }
102        ++$testCasesTotal;
103    }
104}
105ob_end_clean();
106
107echo "Executed tests\n";
108if ($failures !== []) {
109    echo "Failures:\n" . implode($failures);
110}
111
112?>
113--EXPECT--
114Executed tests
115