Skip to content

Commit 7d6282e

Browse files
committed
fix: Unify the usage of () after class instances (including anonymous classes)
According to chapter 4: > ## 4. Classes, Properties, and Methods > > The term "class" refers to all classes, interfaces, and traits. > > Any closing brace MUST NOT be followed by any comment or statement on the same line. > > When instantiating a new class, parentheses MUST always be present even when there are no arguments passed to the constructor. This MR updates the spec to adhere to that rule on anonymous classes too. (taken from moved from php-fig/fig-standards#1283 but also builds upon php-fig#17)
1 parent b5cac84 commit 7d6282e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

spec.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -1055,24 +1055,27 @@ in the above section.
10551055
```php
10561056
<?php
10571057

1058-
$instance = new class {};
1059-
```
1058+
$instance = new class () {};
1059+
~~~
10601060

10611061
The opening brace MAY be on the same line as the `class` keyword so long as
10621062
the list of `implements` interfaces does not wrap. If the list of interfaces
10631063
wraps, the brace MUST be placed on the line immediately following the last
10641064
interface.
10651065

1066+
This also includes the use of parentheses due to directly instantiating the
1067+
declared class.
1068+
10661069
```php
10671070
<?php
10681071

10691072
// Brace on the same line
1070-
$instance = new class extends \Foo implements \HandleableInterface {
1073+
$instance = new class () extends \Foo implements \HandleableInterface {
10711074
// Class content
10721075
};
10731076

10741077
// Brace on the next line
1075-
$instance = new class extends \Foo implements
1078+
$instance = new class () extends \Foo implements
10761079
\ArrayAccess,
10771080
\Countable,
10781081
\Serializable

0 commit comments

Comments
 (0)