1Valid usages of reserved keywords as identifiers
2-----
3<?php
4
5class Test {
6    function array() {}
7    function public() {}
8
9    static function list() {}
10    static function protected() {}
11
12    public $class;
13    public $private;
14
15    const TRAIT = 3, FINAL = 4;
16
17    const __CLASS__ = 1, __TRAIT__ = 2, __FUNCTION__ = 3, __METHOD__ = 4, __LINE__ = 5,
18          __FILE__ = 6, __DIR__ = 7, __NAMESPACE__ = 8;
19    // __halt_compiler does not work
20}
21
22$t = new Test;
23$t->array();
24$t->public();
25
26Test::list();
27Test::protected();
28
29$t->class;
30$t->private;
31
32Test::TRAIT;
33Test::FINAL;
34
35class Foo {
36    use TraitA, TraitB {
37        TraitA::catch insteadof namespace\TraitB;
38        TraitA::list as foreach;
39        TraitB::throw as protected public;
40        TraitB::self as protected;
41        exit as die;
42        \TraitC::exit as bye;
43        namespace\TraitC::exit as byebye;
44        TraitA::
45            //
46            /** doc comment */
47            #
48        catch /* comment */
49            // comment
50            # comment
51        insteadof TraitB;
52    }
53}
54-----
55array(
56    0: Stmt_Class(
57        attrGroups: array(
58        )
59        flags: 0
60        name: Identifier(
61            name: Test
62        )
63        extends: null
64        implements: array(
65        )
66        stmts: array(
67            0: Stmt_ClassMethod(
68                attrGroups: array(
69                )
70                flags: 0
71                byRef: false
72                name: Identifier(
73                    name: array
74                )
75                params: array(
76                )
77                returnType: null
78                stmts: array(
79                )
80            )
81            1: Stmt_ClassMethod(
82                attrGroups: array(
83                )
84                flags: 0
85                byRef: false
86                name: Identifier(
87                    name: public
88                )
89                params: array(
90                )
91                returnType: null
92                stmts: array(
93                )
94            )
95            2: Stmt_ClassMethod(
96                attrGroups: array(
97                )
98                flags: STATIC (8)
99                byRef: false
100                name: Identifier(
101                    name: list
102                )
103                params: array(
104                )
105                returnType: null
106                stmts: array(
107                )
108            )
109            3: Stmt_ClassMethod(
110                attrGroups: array(
111                )
112                flags: STATIC (8)
113                byRef: false
114                name: Identifier(
115                    name: protected
116                )
117                params: array(
118                )
119                returnType: null
120                stmts: array(
121                )
122            )
123            4: Stmt_Property(
124                attrGroups: array(
125                )
126                flags: PUBLIC (1)
127                type: null
128                props: array(
129                    0: PropertyItem(
130                        name: VarLikeIdentifier(
131                            name: class
132                        )
133                        default: null
134                    )
135                )
136                hooks: array(
137                )
138            )
139            5: Stmt_Property(
140                attrGroups: array(
141                )
142                flags: PUBLIC (1)
143                type: null
144                props: array(
145                    0: PropertyItem(
146                        name: VarLikeIdentifier(
147                            name: private
148                        )
149                        default: null
150                    )
151                )
152                hooks: array(
153                )
154            )
155            6: Stmt_ClassConst(
156                attrGroups: array(
157                )
158                flags: 0
159                type: null
160                consts: array(
161                    0: Const(
162                        name: Identifier(
163                            name: TRAIT
164                        )
165                        value: Scalar_Int(
166                            value: 3
167                        )
168                    )
169                    1: Const(
170                        name: Identifier(
171                            name: FINAL
172                        )
173                        value: Scalar_Int(
174                            value: 4
175                        )
176                    )
177                )
178            )
179            7: Stmt_ClassConst(
180                attrGroups: array(
181                )
182                flags: 0
183                type: null
184                consts: array(
185                    0: Const(
186                        name: Identifier(
187                            name: __CLASS__
188                        )
189                        value: Scalar_Int(
190                            value: 1
191                        )
192                    )
193                    1: Const(
194                        name: Identifier(
195                            name: __TRAIT__
196                        )
197                        value: Scalar_Int(
198                            value: 2
199                        )
200                    )
201                    2: Const(
202                        name: Identifier(
203                            name: __FUNCTION__
204                        )
205                        value: Scalar_Int(
206                            value: 3
207                        )
208                    )
209                    3: Const(
210                        name: Identifier(
211                            name: __METHOD__
212                        )
213                        value: Scalar_Int(
214                            value: 4
215                        )
216                    )
217                    4: Const(
218                        name: Identifier(
219                            name: __LINE__
220                        )
221                        value: Scalar_Int(
222                            value: 5
223                        )
224                    )
225                    5: Const(
226                        name: Identifier(
227                            name: __FILE__
228                        )
229                        value: Scalar_Int(
230                            value: 6
231                        )
232                    )
233                    6: Const(
234                        name: Identifier(
235                            name: __DIR__
236                        )
237                        value: Scalar_Int(
238                            value: 7
239                        )
240                    )
241                    7: Const(
242                        name: Identifier(
243                            name: __NAMESPACE__
244                        )
245                        value: Scalar_Int(
246                            value: 8
247                        )
248                    )
249                )
250            )
251            8: Stmt_Nop(
252                comments: array(
253                    0: // __halt_compiler does not work
254                )
255            )
256        )
257    )
258    1: Stmt_Expression(
259        expr: Expr_Assign(
260            var: Expr_Variable(
261                name: t
262            )
263            expr: Expr_New(
264                class: Name(
265                    name: Test
266                )
267                args: array(
268                )
269            )
270        )
271    )
272    2: Stmt_Expression(
273        expr: Expr_MethodCall(
274            var: Expr_Variable(
275                name: t
276            )
277            name: Identifier(
278                name: array
279            )
280            args: array(
281            )
282        )
283    )
284    3: Stmt_Expression(
285        expr: Expr_MethodCall(
286            var: Expr_Variable(
287                name: t
288            )
289            name: Identifier(
290                name: public
291            )
292            args: array(
293            )
294        )
295    )
296    4: Stmt_Expression(
297        expr: Expr_StaticCall(
298            class: Name(
299                name: Test
300            )
301            name: Identifier(
302                name: list
303            )
304            args: array(
305            )
306        )
307    )
308    5: Stmt_Expression(
309        expr: Expr_StaticCall(
310            class: Name(
311                name: Test
312            )
313            name: Identifier(
314                name: protected
315            )
316            args: array(
317            )
318        )
319    )
320    6: Stmt_Expression(
321        expr: Expr_PropertyFetch(
322            var: Expr_Variable(
323                name: t
324            )
325            name: Identifier(
326                name: class
327            )
328        )
329    )
330    7: Stmt_Expression(
331        expr: Expr_PropertyFetch(
332            var: Expr_Variable(
333                name: t
334            )
335            name: Identifier(
336                name: private
337            )
338        )
339    )
340    8: Stmt_Expression(
341        expr: Expr_ClassConstFetch(
342            class: Name(
343                name: Test
344            )
345            name: Identifier(
346                name: TRAIT
347            )
348        )
349    )
350    9: Stmt_Expression(
351        expr: Expr_ClassConstFetch(
352            class: Name(
353                name: Test
354            )
355            name: Identifier(
356                name: FINAL
357            )
358        )
359    )
360    10: Stmt_Class(
361        attrGroups: array(
362        )
363        flags: 0
364        name: Identifier(
365            name: Foo
366        )
367        extends: null
368        implements: array(
369        )
370        stmts: array(
371            0: Stmt_TraitUse(
372                traits: array(
373                    0: Name(
374                        name: TraitA
375                    )
376                    1: Name(
377                        name: TraitB
378                    )
379                )
380                adaptations: array(
381                    0: Stmt_TraitUseAdaptation_Precedence(
382                        trait: Name(
383                            name: TraitA
384                        )
385                        method: Identifier(
386                            name: catch
387                        )
388                        insteadof: array(
389                            0: Name_Relative(
390                                name: TraitB
391                            )
392                        )
393                    )
394                    1: Stmt_TraitUseAdaptation_Alias(
395                        trait: Name(
396                            name: TraitA
397                        )
398                        method: Identifier(
399                            name: list
400                        )
401                        newModifier: null
402                        newName: Identifier(
403                            name: foreach
404                        )
405                    )
406                    2: Stmt_TraitUseAdaptation_Alias(
407                        trait: Name(
408                            name: TraitB
409                        )
410                        method: Identifier(
411                            name: throw
412                        )
413                        newModifier: PROTECTED (2)
414                        newName: Identifier(
415                            name: public
416                        )
417                    )
418                    3: Stmt_TraitUseAdaptation_Alias(
419                        trait: Name(
420                            name: TraitB
421                        )
422                        method: Identifier(
423                            name: self
424                        )
425                        newModifier: PROTECTED (2)
426                        newName: null
427                    )
428                    4: Stmt_TraitUseAdaptation_Alias(
429                        trait: null
430                        method: Identifier(
431                            name: exit
432                        )
433                        newModifier: null
434                        newName: Identifier(
435                            name: die
436                        )
437                    )
438                    5: Stmt_TraitUseAdaptation_Alias(
439                        trait: Name_FullyQualified(
440                            name: TraitC
441                        )
442                        method: Identifier(
443                            name: exit
444                        )
445                        newModifier: null
446                        newName: Identifier(
447                            name: bye
448                        )
449                    )
450                    6: Stmt_TraitUseAdaptation_Alias(
451                        trait: Name_Relative(
452                            name: TraitC
453                        )
454                        method: Identifier(
455                            name: exit
456                        )
457                        newModifier: null
458                        newName: Identifier(
459                            name: byebye
460                        )
461                    )
462                    7: Stmt_TraitUseAdaptation_Precedence(
463                        trait: Name(
464                            name: TraitA
465                        )
466                        method: Identifier(
467                            name: catch
468                            comments: array(
469                                0: //
470                                1: /** doc comment */
471                                2: #
472                            )
473                        )
474                        insteadof: array(
475                            0: Name(
476                                name: TraitB
477                            )
478                        )
479                    )
480                )
481            )
482        )
483    )
484)
485