xref: /PHP-8.4/ext/opcache/tests/opt/sccp_004.phpt (revision e48a5c14)
1--TEST--
2SCCP 004: 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=
9zend_test.observer.enabled=0
10--EXTENSIONS--
11opcache
12--FILE--
13<?php
14function foo(int $x) {
15    $a = [1,2,3];
16    $a[2] = $x;
17    $i = 1;
18    $c = $i < 2;
19    if ($c) {
20        $k = 2 * $i;
21        $a[$k] = $i;
22//		$a[$k]++;
23        echo isset($a[$k]);
24//		$a[$k] += 5;
25    }
26    echo $a[2];
27}
28?>
29--EXPECTF--
30$_main:
31     ; (lines=1, args=0, vars=0, tmps=0)
32     ; (after optimizer)
33     ; %ssccp_004.php:1-17
340000 RETURN int(1)
35
36foo:
37     ; (lines=4, args=1, vars=1, tmps=0)
38     ; (after optimizer)
39     ; %ssccp_004.php:2-15
400000 CV0($x) = RECV 1
410001 ECHO string("1")
420002 ECHO string("1")
430003 RETURN null
44