xref: /php-ast/tests/mixed_type.phpt (revision 260678d4)
1--TEST--
2Mixed types in PHP 8.0
3--FILE--
4<?php
5
6require __DIR__ . '/../util.php';
7
8$code = <<<'PHP'
9<?php
10class Xyz {
11    public function test(mixed $x) : mixed {
12        return $this;
13    }
14}
15PHP;
16
17$node = ast\parse_code($code, $version=70);
18echo ast_dump($node), "\n";
19$node = ast\parse_code($code, $version=80);
20echo ast_dump($node), "\n";
21--EXPECTF--
22AST_STMT_LIST
23    0: AST_CLASS
24        name: "Xyz"
25        docComment: null
26        extends: null
27        implements: null
28        stmts: AST_STMT_LIST
29            0: AST_METHOD
30                flags: MODIFIER_PUBLIC (%d)
31                name: "test"
32                docComment: null
33                params: AST_PARAM_LIST
34                    0: AST_PARAM
35                        type: AST_NAME
36                            flags: NAME_NOT_FQ (%d)
37                            name: "mixed"
38                        name: "x"
39                        default: null
40                stmts: AST_STMT_LIST
41                    0: AST_RETURN
42                        expr: AST_VAR
43                            name: "this"
44                returnType: AST_NAME
45                    flags: NAME_NOT_FQ (%d)
46                    name: "mixed"
47                __declId: 0
48        __declId: 1
49AST_STMT_LIST
50    0: AST_CLASS
51        name: "Xyz"
52        docComment: null
53        extends: null
54        implements: null
55        stmts: AST_STMT_LIST
56            0: AST_METHOD
57                flags: MODIFIER_PUBLIC (%d)
58                name: "test"
59                docComment: null
60                params: AST_PARAM_LIST
61                    0: AST_PARAM
62                        type: AST_TYPE
63                            flags: TYPE_MIXED (%d)
64                        name: "x"
65                        default: null
66                        attributes: null
67                        docComment: null
68                stmts: AST_STMT_LIST
69                    0: AST_RETURN
70                        expr: AST_VAR
71                            name: "this"
72                returnType: AST_TYPE
73                    flags: TYPE_MIXED (%d)
74                attributes: null
75                __declId: 0
76        attributes: null
77        __declId: 1