Skip to content

Commit 0cf22f0

Browse files
authored
Merge branch 'master' into no-body
2 parents e222af2 + cd79134 commit 0cf22f0

File tree

1 file changed

+111
-4
lines changed

1 file changed

+111
-4
lines changed

spec.md

Lines changed: 111 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,12 +544,12 @@ class Point
544544
}
545545
```
546546

547-
### 4.5 Method and Function Arguments
547+
### 4.5 Method and Function Parameters
548548

549549
In the argument list, there MUST NOT be a space before each comma, and there
550550
MUST be one space after each comma.
551551

552-
Method and function arguments with default values MUST go at the end of the argument
552+
Method and function parameters with default values MUST go at the end of the argument
553553
list.
554554

555555
```php
@@ -664,7 +664,7 @@ public function process(string $algorithm, &...$parts)
664664

665665
### 4.6 Modifier Keywords
666666

667-
Properties and methods of a class have numerous keyword modifiers that alter how the
667+
Classes, properties, and methods have numerous keyword modifiers that alter how the
668668
engine and language handles them. When present, they MUST be in the following order:
669669

670670
* Inheritance modifier: `abstract` or `final`
@@ -745,6 +745,13 @@ $app->get('/hello/{name}', function ($name) use ($app) {
745745
});
746746
```
747747

748+
If using named arguments, there MUST NOT be a space between the argument name
749+
and colon, and there MUST be a single space between the colon and the argument value.
750+
751+
```php
752+
somefunction($a, b: $b, c: 'c');
753+
```
754+
748755
Method chaining MAY be put on separate lines, where each subsequent line is indented once. When doing so, the first
749756
method MUST be on the next line.
750757

@@ -1021,7 +1028,9 @@ $i++;
10211028
++$j;
10221029
```
10231030

1024-
Type casting operators MUST NOT have any space within the parentheses:
1031+
Type casting operators MUST NOT have any space within the parentheses and MUST be separated from the variable they are
1032+
operating on by exactly one space:
1033+
10251034
```php
10261035
$intValue = (int) $input;
10271036
```
@@ -1348,6 +1357,104 @@ function allowed()
13481357
}
13491358
```
13501359

1360+
## 11. Attributes
1361+
1362+
### 11.1 Basics
1363+
1364+
Attribute names MUST immediately follow the opening attribute block indicator `#[` with no space.
1365+
1366+
If an attribute has no arguments, the `()` MUST be omitted.
1367+
1368+
The closing attribute block indicator `]` MUST follow the last character of the attribute name or the closing `)` of
1369+
its argument list, with no preceding space.
1370+
1371+
The construct `#[...]` is referred to as an "attribute block" in this document.
1372+
1373+
### 11.2 Placement
1374+
1375+
Attributes on classes, methods, functions, constants and properties MUST
1376+
be placed on their own line, immediately prior to the structure being described.
1377+
1378+
For attributes on parameters, if the parameter list is presented on a single line,
1379+
the attribute MUST be placed inline with the parameter it describes, separated by a single space.
1380+
If the parameter list is split into multiple lines for any reason, the attribute MUST be placed on
1381+
its own line prior to the parameter, indented the same as the parameter. If the parameter list
1382+
is split into multiple lines, a blank line MAY be included between one parameter and the attributes
1383+
of the following parameter in order to aid readability.
1384+
1385+
If a comment docblock is present on a structure that also includes an attribute, the comment block MUST
1386+
come first, followed by any attributes, followed by the structure itself. There MUST NOT be any blank lines
1387+
between the docblock and attributes, or the attributes and the structure.
1388+
1389+
If two separate attribute blocks are used in a multi-line context, they MUST be on separate lines with no blank
1390+
lines between them.
1391+
1392+
### 11.3 Compound attributes
1393+
1394+
If multiple attributes are placed in the same attribute block, they MUST be separated by a comma with a space
1395+
following but no space preceding. If the attribute list is split into multiple lines for any reason, then the
1396+
attributes MUST be placed in separate attribute blocks. Those blocks may themselves contain multiple
1397+
attributes provided this rule is respected.
1398+
1399+
If an attribute's argument list is split into multiple lines for any reason, then:
1400+
1401+
* The attribute MUST be the only one in its attribute block.
1402+
* The attribute arguments MUST follow the same rules as defined for multiline function calls.
1403+
1404+
### 11.4 Example
1405+
1406+
The following is an example of valid attribute usage.
1407+
1408+
```php
1409+
#[Foo]
1410+
#[Bar('baz')]
1411+
class Demo
1412+
{
1413+
#[Beep]
1414+
private Foo $foo;
1415+
1416+
public function __construct(
1417+
#[Load(context: 'foo', bar: true)]
1418+
private readonly FooService $fooService,
1419+
1420+
#[LoadProxy(context: 'bar')]
1421+
private readonly BarService $barService,
1422+
) {}
1423+
1424+
/**
1425+
* Sets the foo.
1426+
*/
1427+
#[Poink('narf'), Narf('poink')]
1428+
public function setFoo(#[Beep] Foo $new): void
1429+
{
1430+
// ...
1431+
}
1432+
1433+
#[Complex(
1434+
prop: 'val',
1435+
other: 5,
1436+
)]
1437+
#[Other, Stuff]
1438+
#[Here]
1439+
public function complicated(
1440+
string $a,
1441+
1442+
#[Decl]
1443+
string $b,
1444+
1445+
#[Complex(
1446+
prop: 'val',
1447+
other: 5,
1448+
)]
1449+
string $c,
1450+
1451+
int $d,
1452+
): string {
1453+
// ...
1454+
}
1455+
}
1456+
```
1457+
13511458
[PSR-1]: https://www.php-fig.org/psr/psr-1/
13521459
[PSR-12]: https://www.php-fig.org/psr/psr-12/
13531460
[keywords]: http://php.net/manual/en/reserved.keywords.php

0 commit comments

Comments
 (0)