xref: /PHP-8.1/ext/opcache/tests/match/002.phpt (revision e9f783fc)
1--TEST--
2Test match jump table optimizer
3--INI--
4opcache.enable=1
5opcache.enable_cli=1
6opcache.opt_debug_level=0x20000
7--EXTENSIONS--
8opcache
9--FILE--
10<?php
11
12function test() {
13    $x = '2';
14    echo match($x) {
15        1, 2, 3, 4, 5 => throw new RuntimeException(),
16        default => "No match\n",
17    };
18}
19test();
20
21function test2() {
22    $x = 2;
23    echo match($x) {
24        '1', '2', '3', '4', '5' => throw new RuntimeException(),
25        default => "No match\n",
26    };
27}
28test2();
29
30?>
31--EXPECTF--
32$_main:
33     ; (lines=5, args=0, vars=0, tmps=0)
34     ; (after optimizer)
35     ; %s
360000 INIT_FCALL 0 %d string("test")
370001 DO_UCALL
380002 INIT_FCALL 0 %d string("test2")
390003 DO_UCALL
400004 RETURN int(1)
41
42test:
43     ; (lines=2, args=0, vars=0, tmps=0)
44     ; (after optimizer)
45     ; %s
460000 ECHO string("No match
47")
480001 RETURN null
49
50test2:
51     ; (lines=2, args=0, vars=0, tmps=0)
52     ; (after optimizer)
53     ; %s
540000 ECHO string("No match
55")
560001 RETURN null
57No match
58No match
59