From 244134613d8e4a4ff99fc5e1adf783a13579db33 Mon Sep 17 00:00:00 2001 From: Larry Garfield Date: Mon, 12 Sep 2022 14:46:11 -0500 Subject: [PATCH 1/2] Allow abbreviated empty bodies. --- spec.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/spec.md b/spec.md index a26ea89..0d04b7a 100644 --- a/spec.md +++ b/spec.md @@ -513,6 +513,29 @@ function fooBarBaz($arg1, &$arg2, $arg3 = []) } ``` +If a function or method contains no statements (such as a no-op implementation or when using +constructor property promotion), then the body SHOULD be abbreviated as `{}` and placed on the same +line as the previous symbol, separated by a space. For example: + +```php +class Point +{ + public function __construct(private int $x, private int $y) {} + + // ... +} +``` + +```php +class Point +{ + public function __construct( + public readonly int $x, + public readonly int $y, + ) {} +} +``` + ### 4.5 Method and Function Arguments In the argument list, there MUST NOT be a space before each comma, and there From e222af2bd5756e62b427b242a4448670e1d834d8 Mon Sep 17 00:00:00 2001 From: Larry Garfield Date: Mon, 12 Sep 2022 15:44:18 -0500 Subject: [PATCH 2/2] Allow for empty class bodies to be abbreviated, too. --- spec.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec.md b/spec.md index 0d04b7a..c171b32 100644 --- a/spec.md +++ b/spec.md @@ -297,6 +297,14 @@ there are no arguments passed to the constructor. new Foo(); ``` +If class contains no additional declarations (such as an exception that exists only extend another exception with a new type), +then the body of the class SHOULD be abbreviated as `{}` and placed on the same line as the previous symbol, +separated by a space. For example: + +```php +class MyException extends \RuntimeException {} +``` + ### 4.1 Extends and Implements The `extends` and `implements` keywords MUST be declared on the same line as