xref: /php-ast/tests/params.phpt (revision 260678d4)
1--TEST--
2Function parameters
3--FILE--
4<?php
5
6require __DIR__ . '/../util.php';
7
8$code = <<<'PHP'
9<?php
10function test($a, ...$b) {}
11function test2(&$a, &...$b) {}
12function test3(array &$a, array &...$b) {}
13PHP;
14
15echo ast_dump(ast\parse_code($code, $version=70)), "\n";
16echo ast_dump(ast\parse_code($code, $version=80)), "\n";
17
18?>
19--EXPECTF--
20AST_STMT_LIST
21    0: AST_FUNC_DECL
22        name: "test"
23        docComment: null
24        params: AST_PARAM_LIST
25            0: AST_PARAM
26                type: null
27                name: "a"
28                default: null
29            1: AST_PARAM
30                flags: PARAM_VARIADIC (%d)
31                type: null
32                name: "b"
33                default: null
34        stmts: AST_STMT_LIST
35        returnType: null
36        __declId: 0
37    1: AST_FUNC_DECL
38        name: "test2"
39        docComment: null
40        params: AST_PARAM_LIST
41            0: AST_PARAM
42                flags: PARAM_REF (%d)
43                type: null
44                name: "a"
45                default: null
46            1: AST_PARAM
47                flags: PARAM_REF | PARAM_VARIADIC (%d)
48                type: null
49                name: "b"
50                default: null
51        stmts: AST_STMT_LIST
52        returnType: null
53        __declId: 1
54    2: AST_FUNC_DECL
55        name: "test3"
56        docComment: null
57        params: AST_PARAM_LIST
58            0: AST_PARAM
59                flags: PARAM_REF (%d)
60                type: AST_TYPE
61                    flags: TYPE_ARRAY (%d)
62                name: "a"
63                default: null
64            1: AST_PARAM
65                flags: PARAM_REF | PARAM_VARIADIC (%d)
66                type: AST_TYPE
67                    flags: TYPE_ARRAY (%d)
68                name: "b"
69                default: null
70        stmts: AST_STMT_LIST
71        returnType: null
72        __declId: 2
73AST_STMT_LIST
74    0: AST_FUNC_DECL
75        name: "test"
76        docComment: null
77        params: AST_PARAM_LIST
78            0: AST_PARAM
79                type: null
80                name: "a"
81                default: null
82                attributes: null
83                docComment: null
84            1: AST_PARAM
85                flags: PARAM_VARIADIC (%d)
86                type: null
87                name: "b"
88                default: null
89                attributes: null
90                docComment: null
91        stmts: AST_STMT_LIST
92        returnType: null
93        attributes: null
94        __declId: 0
95    1: AST_FUNC_DECL
96        name: "test2"
97        docComment: null
98        params: AST_PARAM_LIST
99            0: AST_PARAM
100                flags: PARAM_REF (%d)
101                type: null
102                name: "a"
103                default: null
104                attributes: null
105                docComment: null
106            1: AST_PARAM
107                flags: PARAM_REF | PARAM_VARIADIC (%d)
108                type: null
109                name: "b"
110                default: null
111                attributes: null
112                docComment: null
113        stmts: AST_STMT_LIST
114        returnType: null
115        attributes: null
116        __declId: 1
117    2: AST_FUNC_DECL
118        name: "test3"
119        docComment: null
120        params: AST_PARAM_LIST
121            0: AST_PARAM
122                flags: PARAM_REF (%d)
123                type: AST_TYPE
124                    flags: TYPE_ARRAY (%d)
125                name: "a"
126                default: null
127                attributes: null
128                docComment: null
129            1: AST_PARAM
130                flags: PARAM_REF | PARAM_VARIADIC (%d)
131                type: AST_TYPE
132                    flags: TYPE_ARRAY (%d)
133                name: "b"
134                default: null
135                attributes: null
136                docComment: null
137        stmts: AST_STMT_LIST
138        returnType: null
139        attributes: null
140        __declId: 2