xref: /php-ast/tests/php80_promotion.phpt (revision 260678d4)
1--TEST--
2Constructor property promotion in PHP 8.0
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
12class Promotion {
13	/** Doc comment for __construct */
14	public function __construct(
15		/** Doc comment for $a */
16		public int $a,
17		private stdClass &$b = null,
18		protected iterable $c = []
19	) {
20	}
21}
22PHP;
23
24$node = ast\parse_code($code, $version=70);
25echo ast_dump($node), "\n";
26--EXPECTF--
27AST_STMT_LIST
28    0: AST_CLASS
29        name: "Promotion"
30        docComment: null
31        extends: null
32        implements: null
33        stmts: AST_STMT_LIST
34            0: AST_METHOD
35                flags: MODIFIER_PUBLIC (%d)
36                name: "__construct"
37                docComment: "/** Doc comment for __construct */"
38                params: AST_PARAM_LIST
39                    0: AST_PARAM
40                        flags: PARAM_MODIFIER_PUBLIC (%d)
41                        type: AST_TYPE
42                            flags: TYPE_LONG (4)
43                        name: "a"
44                        default: null
45                    1: AST_PARAM
46                        flags: PARAM_REF | PARAM_MODIFIER_PRIVATE (%d)
47                        type: AST_NAME
48                            flags: NAME_NOT_FQ (1)
49                            name: "stdClass"
50                        name: "b"
51                        default: AST_CONST
52                            name: AST_NAME
53                                flags: NAME_NOT_FQ (1)
54                                name: "null"
55                    2: AST_PARAM
56                        flags: PARAM_MODIFIER_PROTECTED (%d)
57                        type: AST_TYPE
58                            flags: TYPE_ITERABLE (13)
59                        name: "c"
60                        default: AST_ARRAY
61                            flags: ARRAY_SYNTAX_SHORT (3)
62                stmts: AST_STMT_LIST
63                returnType: null
64                __declId: 0
65        __declId: 1
66