1Property hooks
2-----
3<?php
4class Test {
5    public $prop {
6        get { return 42; }
7        set { echo $value; }
8    }
9    private $prop2 {
10        get => 42;
11        set => $value;
12    }
13    abstract $prop3 {
14        &get;
15        set;
16    }
17    public $prop4 {
18        final get { return 42; }
19        set(string $value) { }
20    }
21}
22-----
23array(
24    0: Stmt_Class(
25        attrGroups: array(
26        )
27        flags: 0
28        name: Identifier(
29            name: Test
30        )
31        extends: null
32        implements: array(
33        )
34        stmts: array(
35            0: Stmt_Property(
36                attrGroups: array(
37                )
38                flags: PUBLIC (1)
39                type: null
40                props: array(
41                    0: PropertyItem(
42                        name: VarLikeIdentifier(
43                            name: prop
44                        )
45                        default: null
46                    )
47                )
48                hooks: array(
49                    0: PropertyHook(
50                        attrGroups: array(
51                        )
52                        flags: 0
53                        byRef: false
54                        name: Identifier(
55                            name: get
56                        )
57                        params: array(
58                        )
59                        body: array(
60                            0: Stmt_Return(
61                                expr: Scalar_Int(
62                                    value: 42
63                                )
64                            )
65                        )
66                    )
67                    1: PropertyHook(
68                        attrGroups: array(
69                        )
70                        flags: 0
71                        byRef: false
72                        name: Identifier(
73                            name: set
74                        )
75                        params: array(
76                        )
77                        body: array(
78                            0: Stmt_Echo(
79                                exprs: array(
80                                    0: Expr_Variable(
81                                        name: value
82                                    )
83                                )
84                            )
85                        )
86                    )
87                )
88            )
89            1: Stmt_Property(
90                attrGroups: array(
91                )
92                flags: PRIVATE (4)
93                type: null
94                props: array(
95                    0: PropertyItem(
96                        name: VarLikeIdentifier(
97                            name: prop2
98                        )
99                        default: null
100                    )
101                )
102                hooks: array(
103                    0: PropertyHook(
104                        attrGroups: array(
105                        )
106                        flags: 0
107                        byRef: false
108                        name: Identifier(
109                            name: get
110                        )
111                        params: array(
112                        )
113                        body: Scalar_Int(
114                            value: 42
115                        )
116                    )
117                    1: PropertyHook(
118                        attrGroups: array(
119                        )
120                        flags: 0
121                        byRef: false
122                        name: Identifier(
123                            name: set
124                        )
125                        params: array(
126                        )
127                        body: Expr_Variable(
128                            name: value
129                        )
130                    )
131                )
132            )
133            2: Stmt_Property(
134                attrGroups: array(
135                )
136                flags: ABSTRACT (16)
137                type: null
138                props: array(
139                    0: PropertyItem(
140                        name: VarLikeIdentifier(
141                            name: prop3
142                        )
143                        default: null
144                    )
145                )
146                hooks: array(
147                    0: PropertyHook(
148                        attrGroups: array(
149                        )
150                        flags: 0
151                        byRef: true
152                        name: Identifier(
153                            name: get
154                        )
155                        params: array(
156                        )
157                        body: null
158                    )
159                    1: PropertyHook(
160                        attrGroups: array(
161                        )
162                        flags: 0
163                        byRef: false
164                        name: Identifier(
165                            name: set
166                        )
167                        params: array(
168                        )
169                        body: null
170                    )
171                )
172            )
173            3: Stmt_Property(
174                attrGroups: array(
175                )
176                flags: PUBLIC (1)
177                type: null
178                props: array(
179                    0: PropertyItem(
180                        name: VarLikeIdentifier(
181                            name: prop4
182                        )
183                        default: null
184                    )
185                )
186                hooks: array(
187                    0: PropertyHook(
188                        attrGroups: array(
189                        )
190                        flags: FINAL (32)
191                        byRef: false
192                        name: Identifier(
193                            name: get
194                        )
195                        params: array(
196                        )
197                        body: array(
198                            0: Stmt_Return(
199                                expr: Scalar_Int(
200                                    value: 42
201                                )
202                            )
203                        )
204                    )
205                    1: PropertyHook(
206                        attrGroups: array(
207                        )
208                        flags: 0
209                        byRef: false
210                        name: Identifier(
211                            name: set
212                        )
213                        params: array(
214                            0: Param(
215                                attrGroups: array(
216                                )
217                                flags: 0
218                                type: Identifier(
219                                    name: string
220                                )
221                                byRef: false
222                                variadic: false
223                                var: Expr_Variable(
224                                    name: value
225                                )
226                                default: null
227                                hooks: array(
228                                )
229                            )
230                        )
231                        body: array(
232                        )
233                    )
234                )
235            )
236        )
237    )
238)
239-----
240<?php
241class Test {
242    public $prop {}
243    public function __construct(public $prop2 {}) {}
244}
245-----
246Property hook list cannot be empty from 3:18 to 3:18
247Property hook list cannot be empty from 4:47 to 4:47
248array(
249    0: Stmt_Class(
250        attrGroups: array(
251        )
252        flags: 0
253        name: Identifier(
254            name: Test
255        )
256        extends: null
257        implements: array(
258        )
259        stmts: array(
260            0: Stmt_Property(
261                attrGroups: array(
262                )
263                flags: PUBLIC (1)
264                type: null
265                props: array(
266                    0: PropertyItem(
267                        name: VarLikeIdentifier(
268                            name: prop
269                        )
270                        default: null
271                    )
272                )
273                hooks: array(
274                )
275            )
276            1: Stmt_ClassMethod(
277                attrGroups: array(
278                )
279                flags: PUBLIC (1)
280                byRef: false
281                name: Identifier(
282                    name: __construct
283                )
284                params: array(
285                    0: Param(
286                        attrGroups: array(
287                        )
288                        flags: PUBLIC (1)
289                        type: null
290                        byRef: false
291                        variadic: false
292                        var: Expr_Variable(
293                            name: prop2
294                        )
295                        default: null
296                        hooks: array(
297                        )
298                    )
299                )
300                returnType: null
301                stmts: array(
302                )
303            )
304        )
305    )
306)
307-----
308<?php
309class Test {
310    public $prop {
311        get() => 42;
312    }
313}
314-----
315get hook must not have a parameter list from 4:12 to 4:12
316array(
317    0: Stmt_Class(
318        attrGroups: array(
319        )
320        flags: 0
321        name: Identifier(
322            name: Test
323        )
324        extends: null
325        implements: array(
326        )
327        stmts: array(
328            0: Stmt_Property(
329                attrGroups: array(
330                )
331                flags: PUBLIC (1)
332                type: null
333                props: array(
334                    0: PropertyItem(
335                        name: VarLikeIdentifier(
336                            name: prop
337                        )
338                        default: null
339                    )
340                )
341                hooks: array(
342                    0: PropertyHook(
343                        attrGroups: array(
344                        )
345                        flags: 0
346                        byRef: false
347                        name: Identifier(
348                            name: get
349                        )
350                        params: array(
351                        )
352                        body: Scalar_Int(
353                            value: 42
354                        )
355                    )
356                )
357            )
358        )
359    )
360)
361-----
362<?php
363class Test {
364    public $prop { FOO => bar; }
365}
366-----
367Unknown hook "FOO", expected "get" or "set" from 3:20 to 3:22
368array(
369    0: Stmt_Class(
370        attrGroups: array(
371        )
372        flags: 0
373        name: Identifier(
374            name: Test
375        )
376        extends: null
377        implements: array(
378        )
379        stmts: array(
380            0: Stmt_Property(
381                attrGroups: array(
382                )
383                flags: PUBLIC (1)
384                type: null
385                props: array(
386                    0: PropertyItem(
387                        name: VarLikeIdentifier(
388                            name: prop
389                        )
390                        default: null
391                    )
392                )
393                hooks: array(
394                    0: PropertyHook(
395                        attrGroups: array(
396                        )
397                        flags: 0
398                        byRef: false
399                        name: Identifier(
400                            name: FOO
401                        )
402                        params: array(
403                        )
404                        body: Expr_ConstFetch(
405                            name: Name(
406                                name: bar
407                            )
408                        )
409                    )
410                )
411            )
412        )
413    )
414)
415-----
416<?php
417class Test {
418    public $prop {
419        public public get;
420        protected get;
421        private get;
422        abstract static get;
423        readonly get;
424    }
425}
426-----
427Cannot use the public modifier on a property hook from 4:9 to 4:14
428Multiple access type modifiers are not allowed from 4:16 to 4:21
429Cannot use the public modifier on a property hook from 4:16 to 4:21
430Cannot use the protected modifier on a property hook from 5:9 to 5:17
431Cannot use the private modifier on a property hook from 6:9 to 6:15
432Cannot use the abstract modifier on a property hook from 7:9 to 7:16
433Cannot use the static modifier on a property hook from 7:18 to 7:23
434Cannot use the readonly modifier on a property hook from 8:9 to 8:16
435array(
436    0: Stmt_Class(
437        attrGroups: array(
438        )
439        flags: 0
440        name: Identifier(
441            name: Test
442        )
443        extends: null
444        implements: array(
445        )
446        stmts: array(
447            0: Stmt_Property(
448                attrGroups: array(
449                )
450                flags: PUBLIC (1)
451                type: null
452                props: array(
453                    0: PropertyItem(
454                        name: VarLikeIdentifier(
455                            name: prop
456                        )
457                        default: null
458                    )
459                )
460                hooks: array(
461                    0: PropertyHook(
462                        attrGroups: array(
463                        )
464                        flags: PUBLIC (1)
465                        byRef: false
466                        name: Identifier(
467                            name: get
468                        )
469                        params: array(
470                        )
471                        body: null
472                    )
473                    1: PropertyHook(
474                        attrGroups: array(
475                        )
476                        flags: PROTECTED (2)
477                        byRef: false
478                        name: Identifier(
479                            name: get
480                        )
481                        params: array(
482                        )
483                        body: null
484                    )
485                    2: PropertyHook(
486                        attrGroups: array(
487                        )
488                        flags: PRIVATE (4)
489                        byRef: false
490                        name: Identifier(
491                            name: get
492                        )
493                        params: array(
494                        )
495                        body: null
496                    )
497                    3: PropertyHook(
498                        attrGroups: array(
499                        )
500                        flags: ABSTRACT | STATIC (24)
501                        byRef: false
502                        name: Identifier(
503                            name: get
504                        )
505                        params: array(
506                        )
507                        body: null
508                    )
509                    4: PropertyHook(
510                        attrGroups: array(
511                        )
512                        flags: READONLY (64)
513                        byRef: false
514                        name: Identifier(
515                            name: get
516                        )
517                        params: array(
518                        )
519                        body: null
520                    )
521                )
522            )
523        )
524    )
525)
526