xref: /php-ast/tests/class_const_types.phpt (revision 71f6a54d)
1--TEST--
2PHP 8.3 class constant types
3--SKIPIF--
4<?php if (PHP_VERSION_ID < 80300) die('skip PHP >= 8.3 only'); ?>
5--FILE--
6<?php
7
8require __DIR__ . '/../util.php';
9
10$code = <<<'PHP'
11<?php
12class Test {
13    public const int X = 1, Y = 2;
14    const ?Foo BAR = XYZ;
15}
16PHP;
17
18echo ast_dump(ast\parse_code($code, $version=90));
19echo "\n\nIn version 100\n";
20echo ast_dump(ast\parse_code($code, $version=100));
21--EXPECT--
22AST_STMT_LIST
23    0: AST_CLASS
24        name: "Test"
25        docComment: null
26        extends: null
27        implements: null
28        stmts: AST_STMT_LIST
29            0: AST_CLASS_CONST_GROUP
30                flags: MODIFIER_PUBLIC (1)
31                const: AST_CLASS_CONST_DECL
32                    0: AST_CONST_ELEM
33                        name: "X"
34                        value: 1
35                        docComment: null
36                    1: AST_CONST_ELEM
37                        name: "Y"
38                        value: 2
39                        docComment: null
40                attributes: null
41            1: AST_CLASS_CONST_GROUP
42                flags: MODIFIER_PUBLIC (1)
43                const: AST_CLASS_CONST_DECL
44                    0: AST_CONST_ELEM
45                        name: "BAR"
46                        value: AST_CONST
47                            name: AST_NAME
48                                flags: NAME_NOT_FQ (1)
49                                name: "XYZ"
50                        docComment: null
51                attributes: null
52        attributes: null
53        type: null
54        __declId: 0
55
56In version 100
57AST_STMT_LIST
58    0: AST_CLASS
59        name: "Test"
60        docComment: null
61        extends: null
62        implements: null
63        stmts: AST_STMT_LIST
64            0: AST_CLASS_CONST_GROUP
65                flags: MODIFIER_PUBLIC (1)
66                const: AST_CLASS_CONST_DECL
67                    0: AST_CONST_ELEM
68                        name: "X"
69                        value: 1
70                        docComment: null
71                    1: AST_CONST_ELEM
72                        name: "Y"
73                        value: 2
74                        docComment: null
75                attributes: null
76                type: AST_TYPE
77                    flags: TYPE_LONG (4)
78            1: AST_CLASS_CONST_GROUP
79                flags: MODIFIER_PUBLIC (1)
80                const: AST_CLASS_CONST_DECL
81                    0: AST_CONST_ELEM
82                        name: "BAR"
83                        value: AST_CONST
84                            name: AST_NAME
85                                flags: NAME_NOT_FQ (1)
86                                name: "XYZ"
87                        docComment: null
88                attributes: null
89                type: AST_NULLABLE_TYPE
90                    type: AST_NAME
91                        flags: NAME_NOT_FQ (1)
92                        name: "Foo"
93        attributes: null
94        type: null
95        __declId: 0
96