File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -117,6 +117,47 @@ Any new types and keywords added to future PHP versions MUST be in lower case.
117117Short form of type keywords MUST be used i.e. ` bool ` instead of ` boolean ` ,
118118` int ` instead of ` integer ` etc.
119119
120+ ### 2.6 Trailing commas
121+
122+ Numerous PHP constructs allow a sequence of values to be separated by a comma,
123+ and the final item may have an optional comma. Examples include array key/value pairs,
124+ function arguments, closure ` use ` statements, ` match() ` statement branches, etc.
125+
126+ If that list is contained on a single line, then the last item MUST NOT have a trailing comma.
127+
128+ If the list is split across multiple lines, then the last item MUST have a trailing comma.
129+
130+ The following are examples of correct comma placement:
131+
132+ ``` php
133+ function beep(string $a, string $b, string $c)
134+ {
135+ // ...
136+ }
137+
138+ function beep(
139+ string $a,
140+ string $b,
141+ string $c,
142+ ) {
143+ // ...
144+ }
145+
146+ $arr = ['a' => 'A', 'b' => 'B', 'c' => 'C'];
147+
148+ $arr = [
149+ 'a' => 'A',
150+ 'b' => 'B',
151+ 'c' => 'C',
152+ ];
153+
154+ $result = match ($a) {
155+ 'foo' => 'Foo',
156+ 'bar' => 'Bar',
157+ default => 'Baz',
158+ };
159+ ```
160+
120161## 3. Declare Statements, Namespace, and Import Statements
121162
122163The header of a PHP file may consist of a number of different blocks. If present,
You can’t perform that action at this time.
0 commit comments