Skip to content

Commit 5e2d262

Browse files
authored
Merge pull request #110 from KorvinSzanto/new-class-no-parenthesis
Recommend omitting wrapping parenthesis when immediately calling a method on a new instance
2 parents d34e77a + e851630 commit 5e2d262

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

spec.md

+17
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,23 @@ separated by a space. For example:
369369
class MyException extends \RuntimeException {}
370370
```
371371

372+
When accessing a class member immeditely after instantiating a new class, the instantiation SHOULD NOT be wrapped in
373+
parenthesis. For example:
374+
375+
```php
376+
new Foo()->someMethod();
377+
new Foo()->someStaticMethod();
378+
new Foo()->someProperty;
379+
new Foo()::someStaticProperty;
380+
new Foo()::SOME_CONSTANT;
381+
```
382+
383+
And the following SHOULD be avoided:
384+
385+
```php
386+
(new Foo())->someMethod();
387+
```
388+
372389
### 4.1 Extends and Implements
373390

374391
The `extends` and `implements` keywords MUST be declared on the same line as

0 commit comments

Comments
 (0)