xref: /PHP-8.1/ext/opcache/tests/match/001.phpt (revision e9f783fc)
1--TEST--
2Match expression string jump table
3--INI--
4opcache.enable=1
5opcache.enable_cli=1
6opcache.opt_debug_level=0x20000
7--EXTENSIONS--
8opcache
9--FILE--
10<?php
11
12function test($char) {
13    return match ($char) {
14        'a' => 'a',
15        'b', 'c' => 'b, c',
16        'd' => 'd',
17        'e', 'f' => 'e, f',
18        'g' => 'g',
19        'h', 'i' => 'h, i',
20    };
21}
22
23foreach (range('a', 'i') as $char) {
24    var_dump(test($char));
25}
26
27?>
28--EXPECTF--
29$_main:
30     ; (lines=15, args=0, vars=1, tmps=2)
31     ; (after optimizer)
32     ; %s
330000 INIT_FCALL 2 %d string("range")
340001 SEND_VAL string("a") 1
350002 SEND_VAL string("i") 2
360003 V2 = DO_ICALL
370004 V1 = FE_RESET_R V2 0013
380005 FE_FETCH_R V1 CV0($char) 0013
390006 INIT_FCALL 1 %d string("var_dump")
400007 INIT_FCALL 1 %d string("test")
410008 SEND_VAR CV0($char) 1
420009 V2 = DO_UCALL
430010 SEND_VAR V2 1
440011 DO_ICALL
450012 JMP 0005
460013 FE_FREE V1
470014 RETURN int(1)
48LIVE RANGES:
49     1: 0005 - 0013 (loop)
50
51test:
52     ; (lines=9, args=1, vars=1, tmps=0)
53     ; (after optimizer)
54     ; %s
550000 CV0($char) = RECV 1
560001 MATCH CV0($char) "a": 0003, "b": 0004, "c": 0004, "d": 0005, "e": 0006, "f": 0006, "g": 0007, "h": 0008, "i": 0008, default: 0002
570002 MATCH_ERROR CV0($char)
580003 RETURN string("a")
590004 RETURN string("b, c")
600005 RETURN string("d")
610006 RETURN string("e, f")
620007 RETURN string("g")
630008 RETURN string("h, i")
64string(1) "a"
65string(4) "b, c"
66string(4) "b, c"
67string(1) "d"
68string(4) "e, f"
69string(4) "e, f"
70string(1) "g"
71string(4) "h, i"
72string(4) "h, i"
73