xref: /PHP-8.2/ext/opcache/tests/bug78015.phpt (revision e9f783fc)
1--TEST--
2Bug #78015: Incorrect evaluation of expressions involving partials array in SCCP
3--EXTENSIONS--
4opcache
5--FILE--
6<?php
7
8$x = 1;
9
10function test1() {
11    global $x;
12    $a = ['b' => [$x], 'c' => [$x]];
13    $d = $a['b'] + $a['c'];
14    return $d;
15}
16
17function test2() {
18    global $x;
19    $a = ['b' => [$x]];
20    $d = !$a['b'];
21    return $d;
22}
23
24function test3() {
25    global $x;
26    $a = ['b' => [$x]];
27    $d = (int) $a['b'];
28    return $d;
29}
30
31function test4() {
32    global $x;
33    $a = ['b' => [$x]];
34    $d = $a['b'] ?: 42;
35    return $d;
36}
37
38function test5() {
39    global $x;
40    $a = ['b' => [$x]];
41    $d = is_array($a['b']);
42    return $d;
43}
44
45function test6() {
46    global $x;
47    $a = ['b' => [$x]];
48    $b = "foo";
49    $d = "$a[b]{$b}bar";
50    return $d;
51}
52
53function test7() {
54    global $x;
55    $a = ['b' => [$x]];
56    $y = 1;
57    foreach ($a['b'] as $_) {
58        $y = 2;
59    }
60    return $y;
61}
62
63function test8($array) {
64    $i = 0;
65    $ret = [[]];
66    foreach ($array as $_) {
67      $i++;
68      $ret = [[
69        'x' => 0,
70        'y' => $i,
71      ]];
72    }
73    return $ret[0];
74}
75
76function test9() {
77    global $x;
78    $a = ['b' => [$x]];
79    return serialize($a['b']);
80}
81
82var_dump(test1());
83var_dump(test2());
84var_dump(test3());
85var_dump(test4());
86var_dump(test5());
87var_dump(test6());
88var_dump(test7());
89var_dump(test8([1]));
90var_dump(test9());
91
92?>
93--EXPECTF--
94array(1) {
95  [0]=>
96  int(1)
97}
98bool(false)
99int(1)
100array(1) {
101  [0]=>
102  int(1)
103}
104bool(true)
105
106Warning: Array to string conversion in %s on line %d
107string(11) "Arrayfoobar"
108int(2)
109array(2) {
110  ["x"]=>
111  int(0)
112  ["y"]=>
113  int(1)
114}
115string(14) "a:1:{i:0;i:1;}"
116