xref: /PHP-8.1/ext/opcache/tests/opt/sccp_002.phpt (revision e9f783fc)
1--TEST--
2SCCP 002: Conditional Constant Propagation of non-escaping array elements
3--INI--
4opcache.enable=1
5opcache.enable_cli=1
6opcache.optimization_level=-1
7opcache.opt_debug_level=0x20000
8opcache.preload=
9--EXTENSIONS--
10opcache
11--FILE--
12<?php
13function foo(int $x) {
14    $a = [$x];
15    $i = 1;
16    $c = $i < 2;
17    if ($c) {
18        $k = 2 * $i;
19        $a[$k] = $i;
20        echo $a[$k];
21    }
22    echo $a[2];
23}
24?>
25--EXPECTF--
26$_main:
27     ; (lines=1, args=0, vars=0, tmps=0)
28     ; (after optimizer)
29     ; %ssccp_002.php:1-14
300000 RETURN int(1)
31
32foo:
33     ; (lines=4, args=1, vars=1, tmps=0)
34     ; (after optimizer)
35     ; %ssccp_002.php:2-12
360000 CV0($x) = RECV 1
370001 ECHO string("1")
380002 ECHO string("1")
390003 RETURN null
40