xref: /php-ast/tests/match_expression.phpt (revision 1b5d767d)
1--TEST--
2Match expression in PHP 8.0
3--SKIPIF--
4<?php if (PHP_VERSION_ID < 80000) die('skip PHP >= 8.0 only'); ?>
5--FILE--
6<?php
7
8require __DIR__ . '/../util.php';
9
10$code = <<<'PHP'
11<?php
12$x = match($y) { 2 => 3, default => 5 };
13
14match(1) {};
15match(my_const) {
16	1, \other_const => $x,
17	default, => 123,
18};
19PHP;
20
21$node = ast\parse_code($code, $version=70);
22echo ast_dump($node), "\n";
23--EXPECTF--
24AST_STMT_LIST
25    0: AST_ASSIGN
26        var: AST_VAR
27            name: "x"
28        expr: AST_MATCH
29            cond: AST_VAR
30                name: "y"
31            stmts: AST_MATCH_ARM_LIST
32                0: AST_MATCH_ARM
33                    cond: AST_EXPR_LIST
34                        0: 2
35                    expr: 3
36                1: AST_MATCH_ARM
37                    cond: null
38                    expr: 5
39    1: AST_MATCH
40        cond: 1
41        stmts: AST_MATCH_ARM_LIST
42    2: AST_MATCH
43        cond: AST_CONST
44            name: AST_NAME
45                flags: NAME_NOT_FQ (%d)
46                name: "my_const"
47        stmts: AST_MATCH_ARM_LIST
48            0: AST_MATCH_ARM
49                cond: AST_EXPR_LIST
50                    0: 1
51                    1: AST_CONST
52                        name: AST_NAME
53                            flags: NAME_FQ (%d)
54                            name: "other_const"
55                expr: AST_VAR
56                    name: "x"
57            1: AST_MATCH_ARM
58                cond: null
59                expr: 123