From bdbf3ee4ca8a35ce655aa5a9c0580894db14ba96 Mon Sep 17 00:00:00 2001 From: Korvin Szanto Date: Tue, 21 Jan 2025 12:47:29 -0800 Subject: [PATCH 1/2] Recommend omitting wrapping parenthesis when immediately calling a method on a new instance --- spec.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spec.md b/spec.md index 0bde576..c3c55e3 100644 --- a/spec.md +++ b/spec.md @@ -308,6 +308,19 @@ separated by a space. For example: class MyException extends \RuntimeException {} ``` +When calling a method immeditely after instantiating a new class, the instantiation SHOULD NOT be wrapped in +parenthesis. For example: + +```php +$methodResult = new Foo()->someMethod(); +``` + +And the following SHOULD be avoided: + +```php +$methodResult = (new Foo())->someMethod(); +``` + ### 4.1 Extends and Implements The `extends` and `implements` keywords MUST be declared on the same line as From e85163021aabfec7c5c87e7471957ced05da91c3 Mon Sep 17 00:00:00 2001 From: Korvin Szanto Date: Tue, 21 Jan 2025 12:53:34 -0800 Subject: [PATCH 2/2] Make it clear that this applies when accessing any class member and not just methods. --- spec.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/spec.md b/spec.md index c3c55e3..b43fae7 100644 --- a/spec.md +++ b/spec.md @@ -308,17 +308,21 @@ separated by a space. For example: class MyException extends \RuntimeException {} ``` -When calling a method immeditely after instantiating a new class, the instantiation SHOULD NOT be wrapped in +When accessing a class member immeditely after instantiating a new class, the instantiation SHOULD NOT be wrapped in parenthesis. For example: ```php -$methodResult = new Foo()->someMethod(); +new Foo()->someMethod(); +new Foo()->someStaticMethod(); +new Foo()->someProperty; +new Foo()::someStaticProperty; +new Foo()::SOME_CONSTANT; ``` And the following SHOULD be avoided: ```php -$methodResult = (new Foo())->someMethod(); +(new Foo())->someMethod(); ``` ### 4.1 Extends and Implements