Skip to content

Commit f89d1c9

Browse files
authored
Merge pull request #44 from Crell/no-body
Allow abbreviated empty bodies.
2 parents cd79134 + 0cf22f0 commit f89d1c9

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

spec.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,14 @@ there are no arguments passed to the constructor.
297297
new Foo();
298298
```
299299

300+
If class contains no additional declarations (such as an exception that exists only extend another exception with a new type),
301+
then the body of the class SHOULD be abbreviated as `{}` and placed on the same line as the previous symbol,
302+
separated by a space. For example:
303+
304+
```php
305+
class MyException extends \RuntimeException {}
306+
```
307+
300308
### 4.1 Extends and Implements
301309

302310
The `extends` and `implements` keywords MUST be declared on the same line as
@@ -513,6 +521,29 @@ function fooBarBaz($arg1, &$arg2, $arg3 = [])
513521
}
514522
```
515523

524+
If a function or method contains no statements (such as a no-op implementation or when using
525+
constructor property promotion), then the body SHOULD be abbreviated as `{}` and placed on the same
526+
line as the previous symbol, separated by a space. For example:
527+
528+
```php
529+
class Point
530+
{
531+
public function __construct(private int $x, private int $y) {}
532+
533+
// ...
534+
}
535+
```
536+
537+
```php
538+
class Point
539+
{
540+
public function __construct(
541+
public readonly int $x,
542+
public readonly int $y,
543+
) {}
544+
}
545+
```
546+
516547
### 4.5 Method and Function Parameters
517548

518549
In the argument list, there MUST NOT be a space before each comma, and there

0 commit comments

Comments
 (0)