xref: /PHP-8.2/ext/opcache/tests/opt/dce_009.phpt (revision e48a5c14)
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=
9zend_test.observer.enabled=0
10--EXTENSIONS--
11opcache
12--FILE--
13<?php
14class Loop {
15    const VALUES = [];
16    public static function test() {
17        echo "Start\n";
18        $y = [];
19        foreach ($y as $x) {
20        }
21        echo "Done\n";
22    }
23    public static function test2() {
24        foreach (self::VALUES as $x) {
25        }
26    }
27    public static function test3() {
28        foreach ([] as $k => &$v) {
29        }
30    }
31}
32Loop::test();
33Loop::test2();
34Loop::test3();
35--EXPECTF--
36$_main:
37     ; (lines=7, args=0, vars=0, tmps=0)
38     ; (after optimizer)
39     ; %sdce_009.php:1-23
400000 INIT_STATIC_METHOD_CALL 0 string("Loop") string("test")
410001 DO_UCALL
420002 INIT_STATIC_METHOD_CALL 0 string("Loop") string("test2")
430003 DO_UCALL
440004 INIT_STATIC_METHOD_CALL 0 string("Loop") string("test3")
450005 DO_UCALL
460006 RETURN int(1)
47
48Loop::test:
49     ; (lines=3, args=0, vars=0, tmps=0)
50     ; (after optimizer)
51     ; %sdce_009.php:4-10
520000 ECHO string("Start
53")
540001 ECHO string("Done
55")
560002 RETURN null
57
58Loop::test2:
59     ; (lines=1, args=0, vars=0, tmps=0)
60     ; (after optimizer)
61     ; %sdce_009.php:11-14
620000 RETURN null
63
64Loop::test3:
65     ; (lines=3, args=0, vars=0, tmps=1)
66     ; (after optimizer)
67     ; %sdce_009.php:15-18
680000 V0 = FE_RESET_RW array(...) 0001
690001 FE_FREE V0
700002 RETURN null
71Start
72Done
73