Skip to content

Added Arrays as Section 12 #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 44 additions & 5 deletions spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -1357,9 +1357,48 @@ function allowed()
}
```

## 11. Attributes
## 11. Arrays

### 11.1 Basics
Arrays MUST be declared using the short array syntax.

```php
<?php

$arr = [];
```

Arrays MUST follow the trailing comma guidelines.

Array declarations MAY be split across multiple lines, where each subsequent line
is indented once. When doing so, the first value in the array MUST be on the
next line, and there MUST be only one value per line.

When the array declaration is split across multiple lines, the opening bracket
MUST be placed on the same line as the equals sign. The closing bracket
MUST be placed on the next line after the last value. There MUST NOT be more
than one value assignment per line. Value assignments MAY use a single line
or multiple lines.

```php
<?php

$arr1 = ['single', 'line', 'declaration'];

$arr2 = [
'multi',
'line',
'declaration',
['values' => 1, 5, 7],
[
'nested',
'array',
],
];
```

## 12. Attributes

### 12.1 Basics

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

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

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

### 11.2 Placement
### 12.2 Placement

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

### 11.3 Compound attributes
### 12.3 Compound attributes

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

### 11.4 Example
### 12.4 Example

The following is an example of valid attribute usage.

Expand Down