xref: /PHP-8.1/ext/opcache/tests/match/004.phpt (revision e9f783fc)
1--TEST--
2Match expression mixed 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($value) {
13    return match ($value) {
14        1 => '1 int',
15        '1' => '1 string',
16        2 => '2 int',
17        '2' => '2 string',
18        3 => '3 int',
19        '3' => '3 string',
20        4 => '4 int',
21        '4' => '4 string',
22        5 => '5 int',
23        '5' => '5 string',
24        default => 'default',
25    };
26}
27
28foreach (range(0, 6) as $number) {
29    var_dump(test($number));
30    var_dump(test((string) $number));
31}
32
33?>
34--EXPECTF--
35$_main:
36     ; (lines=22, args=0, vars=1, tmps=2)
37     ; (after optimizer)
38     ; %s.php:1-25
390000 INIT_FCALL 2 %d string("range")
400001 SEND_VAL int(0) 1
410002 SEND_VAL int(6) 2
420003 V2 = DO_ICALL
430004 V1 = FE_RESET_R V2 0020
440005 FE_FETCH_R V1 CV0($number) 0020
450006 INIT_FCALL 1 %d string("var_dump")
460007 INIT_FCALL 1 %d string("test")
470008 SEND_VAR CV0($number) 1
480009 V2 = DO_UCALL
490010 SEND_VAR V2 1
500011 DO_ICALL
510012 INIT_FCALL 1 %d string("var_dump")
520013 INIT_FCALL 1 %d string("test")
530014 T2 = CAST (string) CV0($number)
540015 SEND_VAL T2 1
550016 V2 = DO_UCALL
560017 SEND_VAR V2 1
570018 DO_ICALL
580019 JMP 0005
590020 FE_FREE V1
600021 RETURN int(1)
61LIVE RANGES:
62     1: 0005 - 0020 (loop)
63
64test:
65     ; (lines=13, args=1, vars=1, tmps=0)
66     ; (after optimizer)
67     ; %s.php:3-17
680000 CV0($value) = RECV 1
690001 MATCH CV0($value) 1: 0002, "1": 0003, 2: 0004, "2": 0005, 3: 0006, "3": 0007, 4: 0008, "4": 0009, 5: 0010, "5": 0011, default: 0012
700002 RETURN string("1 int")
710003 RETURN string("1 string")
720004 RETURN string("2 int")
730005 RETURN string("2 string")
740006 RETURN string("3 int")
750007 RETURN string("3 string")
760008 RETURN string("4 int")
770009 RETURN string("4 string")
780010 RETURN string("5 int")
790011 RETURN string("5 string")
800012 RETURN string("default")
81string(7) "default"
82string(7) "default"
83string(5) "1 int"
84string(8) "1 string"
85string(5) "2 int"
86string(8) "2 string"
87string(5) "3 int"
88string(8) "3 string"
89string(5) "4 int"
90string(8) "4 string"
91string(5) "5 int"
92string(8) "5 string"
93string(7) "default"
94string(7) "default"
95