xref: /php-ast/tests/attributes_01.phpt (revision 260678d4)
1--TEST--
2Attributes in PHP 8.0 on globals
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
12namespace NS;
13
14#[SomeAttribute]
15function test(#[namespace\SomeAttribute(2+2)] Type $arg) {
16}
17
18$x = #[SomeAttribute] function () {};
19
20$y = #[SomeAttribute] fn (#[\SomeAttribute] $a) => $x;
21PHP;
22
23echo ast_dump(ast\parse_code($code, $version=70));
24--EXPECTF--
25AST_STMT_LIST
26    0: AST_NAMESPACE
27        name: "NS"
28        stmts: null
29    1: AST_FUNC_DECL
30        name: "test"
31        docComment: null
32        params: AST_PARAM_LIST
33            0: AST_PARAM
34                type: AST_NAME
35                    flags: NAME_NOT_FQ (%d)
36                    name: "Type"
37                name: "arg"
38                default: null
39        stmts: AST_STMT_LIST
40        returnType: null
41        __declId: 0
42    2: AST_ASSIGN
43        var: AST_VAR
44            name: "x"
45        expr: AST_CLOSURE
46            name: "{closure}"
47            docComment: null
48            params: AST_PARAM_LIST
49            uses: null
50            stmts: AST_STMT_LIST
51            returnType: null
52            __declId: 1
53    3: AST_ASSIGN
54        var: AST_VAR
55            name: "y"
56        expr: AST_ARROW_FUNC
57            name: "{closure}"
58            docComment: null
59            params: AST_PARAM_LIST
60                0: AST_PARAM
61                    type: null
62                    name: "a"
63                    default: null
64            stmts: AST_RETURN
65                expr: AST_VAR
66                    name: "x"
67            returnType: null
68            __declId: 2