xref: /PHP-8.3/ext/opcache/tests/match/001.phpt (revision e48a5c14)
1--TEST--
2Match expression string jump table
3--INI--
4opcache.enable=1
5opcache.enable_cli=1
6opcache.opt_debug_level=0x20000
7zend_test.observer.enabled=0
8--EXTENSIONS--
9opcache
10--FILE--
11<?php
12
13function test($char) {
14    return match ($char) {
15        'a' => 'a',
16        'b', 'c' => 'b, c',
17        'd' => 'd',
18        'e', 'f' => 'e, f',
19        'g' => 'g',
20        'h', 'i' => 'h, i',
21    };
22}
23
24foreach (range('a', 'i') as $char) {
25    var_dump(test($char));
26}
27
28?>
29--EXPECTF--
30$_main:
31     ; (lines=15, args=0, vars=1, tmps=2)
32     ; (after optimizer)
33     ; %s
340000 INIT_FCALL 2 %d string("range")
350001 SEND_VAL string("a") 1
360002 SEND_VAL string("i") 2
370003 V2 = DO_ICALL
380004 V1 = FE_RESET_R V2 0013
390005 FE_FETCH_R V1 CV0($char) 0013
400006 INIT_FCALL 1 %d string("var_dump")
410007 INIT_FCALL 1 %d string("test")
420008 SEND_VAR CV0($char) 1
430009 V2 = DO_UCALL
440010 SEND_VAR V2 1
450011 DO_ICALL
460012 JMP 0005
470013 FE_FREE V1
480014 RETURN int(1)
49LIVE RANGES:
50     1: 0005 - 0013 (loop)
51
52test:
53     ; (lines=9, args=1, vars=1, tmps=0)
54     ; (after optimizer)
55     ; %s
560000 CV0($char) = RECV 1
570001 MATCH CV0($char) "a": 0003, "b": 0004, "c": 0004, "d": 0005, "e": 0006, "f": 0006, "g": 0007, "h": 0008, "i": 0008, default: 0002
580002 MATCH_ERROR CV0($char)
590003 RETURN string("a")
600004 RETURN string("b, c")
610005 RETURN string("d")
620006 RETURN string("e, f")
630007 RETURN string("g")
640008 RETURN string("h, i")
65string(1) "a"
66string(4) "b, c"
67string(4) "b, c"
68string(1) "d"
69string(4) "e, f"
70string(4) "e, f"
71string(1) "g"
72string(4) "h, i"
73string(4) "h, i"
74