xref: /PHP-8.1/ext/opcache/tests/opt/dce_009.phpt (revision 0826a548)
1--TEST--
2DCE 009: Foreach over empty array is a no-op
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
13class Loop {
14    const VALUES = [];
15    public static function test() {
16        echo "Start\n";
17        $y = [];
18        foreach ($y as $x) {
19        }
20        echo "Done\n";
21    }
22    public static function test2() {
23        foreach (self::VALUES as $x) {
24        }
25    }
26    public static function test3() {
27        foreach ([] as $k => &$v) {
28        }
29    }
30}
31Loop::test();
32Loop::test2();
33Loop::test3();
34--EXPECTF--
35$_main:
36     ; (lines=7, args=0, vars=0, tmps=0)
37     ; (after optimizer)
38     ; %sdce_009.php:1-23
390000 INIT_STATIC_METHOD_CALL 0 string("Loop") string("test")
400001 DO_UCALL
410002 INIT_STATIC_METHOD_CALL 0 string("Loop") string("test2")
420003 DO_UCALL
430004 INIT_STATIC_METHOD_CALL 0 string("Loop") string("test3")
440005 DO_UCALL
450006 RETURN int(1)
46
47Loop::test:
48     ; (lines=3, args=0, vars=0, tmps=0)
49     ; (after optimizer)
50     ; %sdce_009.php:4-10
510000 ECHO string("Start
52")
530001 ECHO string("Done
54")
550002 RETURN null
56
57Loop::test2:
58     ; (lines=1, args=0, vars=0, tmps=0)
59     ; (after optimizer)
60     ; %sdce_009.php:11-14
610000 RETURN null
62
63Loop::test3:
64     ; (lines=3, args=0, vars=0, tmps=1)
65     ; (after optimizer)
66     ; %sdce_009.php:15-18
670000 V0 = FE_RESET_RW array(...) 0001
680001 FE_FREE V0
690002 RETURN null
70Start
71Done
72