xref: /PHP-8.2/ext/opcache/tests/match/002.phpt (revision e48a5c14)
1--TEST--
2Test match jump table optimizer
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() {
14    $x = '2';
15    echo match($x) {
16        1, 2, 3, 4, 5 => throw new RuntimeException(),
17        default => "No match\n",
18    };
19}
20test();
21
22function test2() {
23    $x = 2;
24    echo match($x) {
25        '1', '2', '3', '4', '5' => throw new RuntimeException(),
26        default => "No match\n",
27    };
28}
29test2();
30
31?>
32--EXPECTF--
33$_main:
34     ; (lines=5, args=0, vars=0, tmps=0)
35     ; (after optimizer)
36     ; %s
370000 INIT_FCALL 0 %d string("test")
380001 DO_UCALL
390002 INIT_FCALL 0 %d string("test2")
400003 DO_UCALL
410004 RETURN int(1)
42
43test:
44     ; (lines=2, args=0, vars=0, tmps=0)
45     ; (after optimizer)
46     ; %s
470000 ECHO string("No match
48")
490001 RETURN null
50
51test2:
52     ; (lines=2, args=0, vars=0, tmps=0)
53     ; (after optimizer)
54     ; %s
550000 ECHO string("No match
56")
570001 RETURN null
58No match
59No match
60