xref: /PHP-8.3/ext/opcache/tests/match/004.phpt (revision e48a5c14)
1--TEST--
2Match expression mixed 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($value) {
14    return match ($value) {
15        1 => '1 int',
16        '1' => '1 string',
17        2 => '2 int',
18        '2' => '2 string',
19        3 => '3 int',
20        '3' => '3 string',
21        4 => '4 int',
22        '4' => '4 string',
23        5 => '5 int',
24        '5' => '5 string',
25        default => 'default',
26    };
27}
28
29foreach (range(0, 6) as $number) {
30    var_dump(test($number));
31    var_dump(test((string) $number));
32}
33
34?>
35--EXPECTF--
36$_main:
37     ; (lines=22, args=0, vars=1, tmps=2)
38     ; (after optimizer)
39     ; %s.php:1-25
400000 INIT_FCALL 2 %d string("range")
410001 SEND_VAL int(0) 1
420002 SEND_VAL int(6) 2
430003 V2 = DO_ICALL
440004 V1 = FE_RESET_R V2 0020
450005 FE_FETCH_R V1 CV0($number) 0020
460006 INIT_FCALL 1 %d string("var_dump")
470007 INIT_FCALL 1 %d string("test")
480008 SEND_VAR CV0($number) 1
490009 V2 = DO_UCALL
500010 SEND_VAR V2 1
510011 DO_ICALL
520012 INIT_FCALL 1 %d string("var_dump")
530013 INIT_FCALL 1 %d string("test")
540014 T2 = CAST (string) CV0($number)
550015 SEND_VAL T2 1
560016 V2 = DO_UCALL
570017 SEND_VAR V2 1
580018 DO_ICALL
590019 JMP 0005
600020 FE_FREE V1
610021 RETURN int(1)
62LIVE RANGES:
63     1: 0005 - 0020 (loop)
64
65test:
66     ; (lines=13, args=1, vars=1, tmps=0)
67     ; (after optimizer)
68     ; %s.php:3-17
690000 CV0($value) = RECV 1
700001 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
710002 RETURN string("1 int")
720003 RETURN string("1 string")
730004 RETURN string("2 int")
740005 RETURN string("2 string")
750006 RETURN string("3 int")
760007 RETURN string("3 string")
770008 RETURN string("4 int")
780009 RETURN string("4 string")
790010 RETURN string("5 int")
800011 RETURN string("5 string")
810012 RETURN string("default")
82string(7) "default"
83string(7) "default"
84string(5) "1 int"
85string(8) "1 string"
86string(5) "2 int"
87string(8) "2 string"
88string(5) "3 int"
89string(8) "3 string"
90string(5) "4 int"
91string(8) "4 string"
92string(5) "5 int"
93string(8) "5 string"
94string(7) "default"
95string(7) "default"
96