@@ -7,22 +7,29 @@ Attributes in PHP 8.0 on classes
77
88require __DIR__ . '/../util.php ' ;
99
10+ // Some edge cases in parsing attributes to compare other parsers against
1011$ code = <<<'PHP'
1112<?php
1213namespace NS;
1314
14- @@ \SomeAttribute()
15+ #[ \SomeAttribute()]
1516class X {
16- @@Attr1
17- @@Attr2(true)
17+ #[Attr1]
18+ #[
19+ Attr2(true), # Line comment on an attribute
20+ ]
1821 public $prop;
1922
20- @@ Attr3
23+ #[ Attr3]
2124 public const CONST_WITH_ATTRIBUTE = 123;
2225
23- @@Attr4
24- public static function hasAttribute() {}
26+ #[Attr4, Attr5()]
27+ public static function hasAttribute(
28+ #[ThisIsAnAttribute, \AnotherAttribute] $parameter
29+ ) {}
2530}
31+ #[Deprecated]
32+ function myGlobal() {}
2633PHP;
2734
2835echo ast_dump (ast \parse_code ($ code , $ version =70 ));
@@ -60,10 +67,23 @@ AST_STMT_LIST
6067 name: "hasAttribute"
6168 docComment: null
6269 params: AST_PARAM_LIST
70+ 0 : AST_PARAM
71+ flags: 0
72+ type: null
73+ name: "parameter"
74+ default : null
6375 stmts: AST_STMT_LIST
6476 returnType: null
6577 __declId: 0
6678 __declId: 1
79+ 2 : AST_FUNC_DECL
80+ flags: 0
81+ name: "myGlobal"
82+ docComment: null
83+ params: AST_PARAM_LIST
84+ stmts: AST_STMT_LIST
85+ returnType: null
86+ __declId: 2
6787In version 80
6888AST_STMT_LIST
6989 0 : AST_NAMESPACE
@@ -86,20 +106,22 @@ AST_STMT_LIST
86106 default : null
87107 docComment: null
88108 attributes: AST_ATTRIBUTE_LIST
89- 0 : AST_ATTRIBUTE
90- class : AST_NAME
91- flags: NAME_NOT_FQ (%d)
92- name: "Attr1"
93- args: null
94- 1 : AST_ATTRIBUTE
95- class : AST_NAME
96- flags: NAME_NOT_FQ (%d)
97- name: "Attr2"
98- args: AST_ARG_LIST
99- 0 : AST_CONST
100- name: AST_NAME
101- flags: NAME_NOT_FQ (%d)
102- name: "true"
109+ 0 : AST_ATTRIBUTE_GROUP
110+ 0 : AST_ATTRIBUTE
111+ class : AST_NAME
112+ flags: NAME_NOT_FQ (%d)
113+ name: "Attr1"
114+ args: null
115+ 1 : AST_ATTRIBUTE_GROUP
116+ 0 : AST_ATTRIBUTE
117+ class : AST_NAME
118+ flags: NAME_NOT_FQ (%d)
119+ name: "Attr2"
120+ args: AST_ARG_LIST
121+ 0 : AST_CONST
122+ name: AST_NAME
123+ flags: NAME_NOT_FQ (%d)
124+ name: "true"
103125 1 : AST_CLASS_CONST_GROUP
104126 flags: MODIFIER_PUBLIC (%d)
105127 const : AST_CLASS_CONST_DECL
@@ -109,24 +131,64 @@ AST_STMT_LIST
109131 value: 123
110132 docComment: null
111133 attributes: AST_ATTRIBUTE_LIST
112- 0 : AST_ATTRIBUTE
113- class : AST_NAME
114- flags: NAME_NOT_FQ (%d)
115- name: "Attr3"
116- args: null
134+ 0 : AST_ATTRIBUTE_GROUP
135+ 0 : AST_ATTRIBUTE
136+ class : AST_NAME
137+ flags: NAME_NOT_FQ (%d)
138+ name: "Attr3"
139+ args: null
117140 2 : AST_METHOD
118141 flags: MODIFIER_PUBLIC | MODIFIER_STATIC (%d)
119142 name: "hasAttribute"
120143 docComment: null
121144 params: AST_PARAM_LIST
145+ 0 : AST_PARAM
146+ flags: 0
147+ type: null
148+ name: "parameter"
149+ default : null
150+ attributes: AST_ATTRIBUTE_LIST
151+ 0 : AST_ATTRIBUTE_GROUP
152+ 0 : AST_ATTRIBUTE
153+ class : AST_NAME
154+ flags: NAME_NOT_FQ (%d)
155+ name: "ThisIsAnAttribute"
156+ args: null
157+ 1 : AST_ATTRIBUTE
158+ class : AST_NAME
159+ flags: NAME_FQ (%d)
160+ name: "AnotherAttribute"
161+ args: null
162+ docComment: null
122163 stmts: AST_STMT_LIST
123164 returnType: null
124165 attributes: AST_ATTRIBUTE_LIST
125- 0 : AST_ATTRIBUTE
126- class : AST_NAME
127- flags: NAME_NOT_FQ (%d)
128- name: "Attr4"
129- args: null
166+ 0 : AST_ATTRIBUTE_GROUP
167+ 0 : AST_ATTRIBUTE
168+ class : AST_NAME
169+ flags: NAME_NOT_FQ (%d)
170+ name: "Attr4"
171+ args: null
172+ 1 : AST_ATTRIBUTE
173+ class : AST_NAME
174+ flags: NAME_NOT_FQ (%d)
175+ name: "Attr5"
176+ args: AST_ARG_LIST
130177 __declId: 0
131178 attributes: null
132- __declId: 1
179+ __declId: 1
180+ 2 : AST_FUNC_DECL
181+ flags: 0
182+ name: "myGlobal"
183+ docComment: null
184+ params: AST_PARAM_LIST
185+ stmts: AST_STMT_LIST
186+ returnType: null
187+ attributes: AST_ATTRIBUTE_LIST
188+ 0 : AST_ATTRIBUTE_GROUP
189+ 0 : AST_ATTRIBUTE
190+ class : AST_NAME
191+ flags: NAME_NOT_FQ (%d)
192+ name: "Deprecated"
193+ args: null
194+ __declId: 2
0 commit comments