xref: /php-ast/tests/001.phpt (revision 260678d4)
1--TEST--
2ast_dump() test
3--SKIPIF--
4<?php if (!extension_loaded("ast")) print "skip"; ?>
5--FILE--
6<?php
7
8require __DIR__ . '/../util.php';
9
10$code = <<<'PHP'
11<?php
12
13/** Test function */
14function test(Type $arg = XYZ) : Ret {
15    if ($arg instanceof Foo\Bar) {
16        return test($arg->foo);
17    } else {
18        return $arg->bar;
19    }
20}
21PHP;
22
23echo ast_dump(ast\parse_code($code, $version=70));
24--EXPECT--
25AST_STMT_LIST
26    0: AST_FUNC_DECL
27        name: "test"
28        docComment: "/** Test function */"
29        params: AST_PARAM_LIST
30            0: AST_PARAM
31                type: AST_NAME
32                    flags: NAME_NOT_FQ (1)
33                    name: "Type"
34                name: "arg"
35                default: AST_CONST
36                    name: AST_NAME
37                        flags: NAME_NOT_FQ (1)
38                        name: "XYZ"
39        stmts: AST_STMT_LIST
40            0: AST_IF
41                0: AST_IF_ELEM
42                    cond: AST_INSTANCEOF
43                        expr: AST_VAR
44                            name: "arg"
45                        class: AST_NAME
46                            flags: NAME_NOT_FQ (1)
47                            name: "Foo\Bar"
48                    stmts: AST_STMT_LIST
49                        0: AST_RETURN
50                            expr: AST_CALL
51                                expr: AST_NAME
52                                    flags: NAME_NOT_FQ (1)
53                                    name: "test"
54                                args: AST_ARG_LIST
55                                    0: AST_PROP
56                                        expr: AST_VAR
57                                            name: "arg"
58                                        prop: "foo"
59                1: AST_IF_ELEM
60                    cond: null
61                    stmts: AST_STMT_LIST
62                        0: AST_RETURN
63                            expr: AST_PROP
64                                expr: AST_VAR
65                                    name: "arg"
66                                prop: "bar"
67        returnType: AST_NAME
68            flags: NAME_NOT_FQ (1)
69            name: "Ret"
70        __declId: 0