xref: /php-src/ext/opcache/tests/match/003.phpt (revision e48a5c14)
1--TEST--
2Match expression long 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($char) {
14    return match ($char) {
15        1 => '1',
16        2, 3 => '2, 3',
17        4 => '4',
18        5, 6 => '5, 6',
19        7 => '7',
20        8, 9 => '8, 9',
21        default => 'default'
22    };
23}
24
25foreach (range(0, 10) as $char) {
26    var_dump(test($char));
27}
28
29?>
30--EXPECTF--
31$_main:
32     ; (lines=15, args=0, vars=1, tmps=2)
33     ; (after optimizer)
34     ; %s
350000 INIT_FCALL 2 %d string("range")
360001 SEND_VAL int(0) 1
370002 SEND_VAL int(10) 2
380003 V2 = DO_ICALL
390004 V1 = FE_RESET_R V2 0013
400005 FE_FETCH_R V1 CV0($char) 0013
410006 INIT_FCALL 1 %d string("var_dump")
420007 INIT_FCALL 1 %d string("test")
430008 SEND_VAR CV0($char) 1
440009 V2 = DO_UCALL
450010 SEND_VAR V2 1
460011 DO_ICALL
470012 JMP 0005
480013 FE_FREE V1
490014 RETURN int(1)
50LIVE RANGES:
51     1: 0005 - 0013 (loop)
52
53test:
54     ; (lines=9, args=1, vars=1, tmps=0)
55     ; (after optimizer)
56     ; %s
570000 CV0($char) = RECV 1
580001 MATCH CV0($char) 1: 0002, 2: 0003, 3: 0003, 4: 0004, 5: 0005, 6: 0005, 7: 0006, 8: 0007, 9: 0007, default: 0008
590002 RETURN string("1")
600003 RETURN string("2, 3")
610004 RETURN string("4")
620005 RETURN string("5, 6")
630006 RETURN string("7")
640007 RETURN string("8, 9")
650008 RETURN string("default")
66string(7) "default"
67string(1) "1"
68string(4) "2, 3"
69string(4) "2, 3"
70string(1) "4"
71string(4) "5, 6"
72string(4) "5, 6"
73string(1) "7"
74string(4) "8, 9"
75string(4) "8, 9"
76string(7) "default"
77