xref: /PHP-Parser/test/code/parser/expr/new.test (revision beba9c52)
1New
2-----
3<?php
4
5new A;
6new A($b);
7
8// class name variations
9new $a();
10new $a['b']();
11new A::$b();
12// DNCR object access
13new $a->b();
14new $a->b->c();
15new $a->b['c']();
16
17// test regression introduces by new dereferencing syntax
18(new A);
19-----
20array(
21    0: Stmt_Expression(
22        expr: Expr_New(
23            class: Name(
24                name: A
25            )
26            args: array(
27            )
28        )
29    )
30    1: Stmt_Expression(
31        expr: Expr_New(
32            class: Name(
33                name: A
34            )
35            args: array(
36                0: Arg(
37                    name: null
38                    value: Expr_Variable(
39                        name: b
40                    )
41                    byRef: false
42                    unpack: false
43                )
44            )
45        )
46    )
47    2: Stmt_Expression(
48        expr: Expr_New(
49            class: Expr_Variable(
50                name: a
51            )
52            args: array(
53            )
54        )
55        comments: array(
56            0: // class name variations
57        )
58    )
59    3: Stmt_Expression(
60        expr: Expr_New(
61            class: Expr_ArrayDimFetch(
62                var: Expr_Variable(
63                    name: a
64                )
65                dim: Scalar_String(
66                    value: b
67                )
68            )
69            args: array(
70            )
71        )
72    )
73    4: Stmt_Expression(
74        expr: Expr_New(
75            class: Expr_StaticPropertyFetch(
76                class: Name(
77                    name: A
78                )
79                name: VarLikeIdentifier(
80                    name: b
81                )
82            )
83            args: array(
84            )
85        )
86    )
87    5: Stmt_Expression(
88        expr: Expr_New(
89            class: Expr_PropertyFetch(
90                var: Expr_Variable(
91                    name: a
92                )
93                name: Identifier(
94                    name: b
95                )
96            )
97            args: array(
98            )
99        )
100        comments: array(
101            0: // DNCR object access
102        )
103    )
104    6: Stmt_Expression(
105        expr: Expr_New(
106            class: Expr_PropertyFetch(
107                var: Expr_PropertyFetch(
108                    var: Expr_Variable(
109                        name: a
110                    )
111                    name: Identifier(
112                        name: b
113                    )
114                )
115                name: Identifier(
116                    name: c
117                )
118            )
119            args: array(
120            )
121        )
122    )
123    7: Stmt_Expression(
124        expr: Expr_New(
125            class: Expr_ArrayDimFetch(
126                var: Expr_PropertyFetch(
127                    var: Expr_Variable(
128                        name: a
129                    )
130                    name: Identifier(
131                        name: b
132                    )
133                )
134                dim: Scalar_String(
135                    value: c
136                )
137            )
138            args: array(
139            )
140        )
141    )
142    8: Stmt_Expression(
143        expr: Expr_New(
144            class: Name(
145                name: A
146            )
147            args: array(
148            )
149        )
150        comments: array(
151            0: // test regression introduces by new dereferencing syntax
152        )
153    )
154)
155