@@ -544,12 +544,12 @@ class Point
544
544
}
545
545
```
546
546
547
- ### 4.5 Method and Function Arguments
547
+ ### 4.5 Method and Function Parameters
548
548
549
549
In the argument list, there MUST NOT be a space before each comma, and there
550
550
MUST be one space after each comma.
551
551
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
553
553
list.
554
554
555
555
``` php
@@ -664,7 +664,7 @@ public function process(string $algorithm, &...$parts)
664
664
665
665
### 4.6 Modifier Keywords
666
666
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
668
668
engine and language handles them. When present, they MUST be in the following order:
669
669
670
670
* Inheritance modifier: ` abstract ` or ` final `
@@ -745,6 +745,13 @@ $app->get('/hello/{name}', function ($name) use ($app) {
745
745
});
746
746
```
747
747
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
+
748
755
Method chaining MAY be put on separate lines, where each subsequent line is indented once. When doing so, the first
749
756
method MUST be on the next line.
750
757
@@ -1021,7 +1028,9 @@ $i++;
1021
1028
++$j;
1022
1029
```
1023
1030
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
+
1025
1034
``` php
1026
1035
$intValue = (int) $input;
1027
1036
```
@@ -1348,6 +1357,104 @@ function allowed()
1348
1357
}
1349
1358
```
1350
1359
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
+
1351
1458
[PSR-1]: https://www.php-fig.org/psr/psr-1/
1352
1459
[PSR-12]: https://www.php-fig.org/psr/psr-12/
1353
1460
[keywords]: http://php.net/manual/en/reserved.keywords.php
0 commit comments