Skip to content

Commit 77cea83

Browse files
authored
Merge pull request #48 from mbniebergall/feature/arrays
Added Arrays as Section 12
2 parents f89d1c9 + 9b25548 commit 77cea83

File tree

1 file changed

+44
-5
lines changed

1 file changed

+44
-5
lines changed

spec.md

+44-5
Original file line numberDiff line numberDiff line change
@@ -1357,9 +1357,48 @@ function allowed()
13571357
}
13581358
```
13591359

1360-
## 11. Attributes
1360+
## 11. Arrays
13611361

1362-
### 11.1 Basics
1362+
Arrays MUST be declared using the short array syntax.
1363+
1364+
```php
1365+
<?php
1366+
1367+
$arr = [];
1368+
```
1369+
1370+
Arrays MUST follow the trailing comma guidelines.
1371+
1372+
Array declarations MAY be split across multiple lines, where each subsequent line
1373+
is indented once. When doing so, the first value in the array MUST be on the
1374+
next line, and there MUST be only one value per line.
1375+
1376+
When the array declaration is split across multiple lines, the opening bracket
1377+
MUST be placed on the same line as the equals sign. The closing bracket
1378+
MUST be placed on the next line after the last value. There MUST NOT be more
1379+
than one value assignment per line. Value assignments MAY use a single line
1380+
or multiple lines.
1381+
1382+
```php
1383+
<?php
1384+
1385+
$arr1 = ['single', 'line', 'declaration'];
1386+
1387+
$arr2 = [
1388+
'multi',
1389+
'line',
1390+
'declaration',
1391+
['values' => 1, 5, 7],
1392+
[
1393+
'nested',
1394+
'array',
1395+
],
1396+
];
1397+
```
1398+
1399+
## 12. Attributes
1400+
1401+
### 12.1 Basics
13631402

13641403
Attribute names MUST immediately follow the opening attribute block indicator `#[` with no space.
13651404

@@ -1370,7 +1409,7 @@ its argument list, with no preceding space.
13701409

13711410
The construct `#[...]` is referred to as an "attribute block" in this document.
13721411

1373-
### 11.2 Placement
1412+
### 12.2 Placement
13741413

13751414
Attributes on classes, methods, functions, constants and properties MUST
13761415
be placed on their own line, immediately prior to the structure being described.
@@ -1389,7 +1428,7 @@ between the docblock and attributes, or the attributes and the structure.
13891428
If two separate attribute blocks are used in a multi-line context, they MUST be on separate lines with no blank
13901429
lines between them.
13911430

1392-
### 11.3 Compound attributes
1431+
### 12.3 Compound attributes
13931432

13941433
If multiple attributes are placed in the same attribute block, they MUST be separated by a comma with a space
13951434
following but no space preceding. If the attribute list is split into multiple lines for any reason, then the
@@ -1401,7 +1440,7 @@ If an attribute's argument list is split into multiple lines for any reason, the
14011440
* The attribute MUST be the only one in its attribute block.
14021441
* The attribute arguments MUST follow the same rules as defined for multiline function calls.
14031442

1404-
### 11.4 Example
1443+
### 12.4 Example
14051444

14061445
The following is an example of valid attribute usage.
14071446

0 commit comments

Comments
 (0)