xref: /PHP-Parser/test/code/parser/expr/arrayDef.test (revision 4e27a17c)
1Array definitions
2-----
3<?php
4
5array();
6array('a');
7array('a', );
8array('a', 'b');
9array('a', &$b, 'c' => 'd', 'e' => &$f);
10
11// short array syntax
12[];
13[1, 2, 3];
14['a' => 'b'];
15-----
16array(
17    0: Stmt_Expression(
18        expr: Expr_Array(
19            items: array(
20            )
21        )
22    )
23    1: Stmt_Expression(
24        expr: Expr_Array(
25            items: array(
26                0: ArrayItem(
27                    key: null
28                    value: Scalar_String(
29                        value: a
30                    )
31                    byRef: false
32                    unpack: false
33                )
34            )
35        )
36    )
37    2: Stmt_Expression(
38        expr: Expr_Array(
39            items: array(
40                0: ArrayItem(
41                    key: null
42                    value: Scalar_String(
43                        value: a
44                    )
45                    byRef: false
46                    unpack: false
47                )
48            )
49        )
50    )
51    3: Stmt_Expression(
52        expr: Expr_Array(
53            items: array(
54                0: ArrayItem(
55                    key: null
56                    value: Scalar_String(
57                        value: a
58                    )
59                    byRef: false
60                    unpack: false
61                )
62                1: ArrayItem(
63                    key: null
64                    value: Scalar_String(
65                        value: b
66                    )
67                    byRef: false
68                    unpack: false
69                )
70            )
71        )
72    )
73    4: Stmt_Expression(
74        expr: Expr_Array(
75            items: array(
76                0: ArrayItem(
77                    key: null
78                    value: Scalar_String(
79                        value: a
80                    )
81                    byRef: false
82                    unpack: false
83                )
84                1: ArrayItem(
85                    key: null
86                    value: Expr_Variable(
87                        name: b
88                    )
89                    byRef: true
90                    unpack: false
91                )
92                2: ArrayItem(
93                    key: Scalar_String(
94                        value: c
95                    )
96                    value: Scalar_String(
97                        value: d
98                    )
99                    byRef: false
100                    unpack: false
101                )
102                3: ArrayItem(
103                    key: Scalar_String(
104                        value: e
105                    )
106                    value: Expr_Variable(
107                        name: f
108                    )
109                    byRef: true
110                    unpack: false
111                )
112            )
113        )
114    )
115    5: Stmt_Expression(
116        expr: Expr_Array(
117            items: array(
118            )
119        )
120        comments: array(
121            0: // short array syntax
122        )
123    )
124    6: Stmt_Expression(
125        expr: Expr_Array(
126            items: array(
127                0: ArrayItem(
128                    key: null
129                    value: Scalar_Int(
130                        value: 1
131                    )
132                    byRef: false
133                    unpack: false
134                )
135                1: ArrayItem(
136                    key: null
137                    value: Scalar_Int(
138                        value: 2
139                    )
140                    byRef: false
141                    unpack: false
142                )
143                2: ArrayItem(
144                    key: null
145                    value: Scalar_Int(
146                        value: 3
147                    )
148                    byRef: false
149                    unpack: false
150                )
151            )
152        )
153    )
154    7: Stmt_Expression(
155        expr: Expr_Array(
156            items: array(
157                0: ArrayItem(
158                    key: Scalar_String(
159                        value: a
160                    )
161                    value: Scalar_String(
162                        value: b
163                    )
164                    byRef: false
165                    unpack: false
166                )
167            )
168        )
169    )
170)
171