Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Unify the usage of () after class instances (including anonymous classes) #24

Closed

Conversation

fruitl00p
Copy link

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/!1283)

The original MR on PHP-Fig also mentioned short closures but !17 already fixes this.

… 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)
spec.md Outdated Show resolved Hide resolved
@Crell
Copy link
Collaborator

Crell commented Jun 23, 2022

I'm not actually sure about doing () on an anon class with no constructor. I don't see that style in practice in the wild, and I don't see how it adds much.

@fruitl00p
Copy link
Author

I fully understand and might even agree with you but the PSR isn't clear ATM and with tools like php-cs-fixer 'interpretting' the psr as they do, it seems like it will place those parenthesis according to their interpretation.

My interpretation follows their reasoning as mentioned in chapter four and without the specific changes mentioned in the closures section to which anon-classes refers. Thus confusion ;)

@TimWolla
Copy link
Contributor

see also php-fig/fig-standards#1206 which:

  • Requires the parentheses.
  • Does not expect a space before the parentheses.

@KorvinSzanto
Copy link
Contributor

I agree with @Crell, I'd prefer seeing this go the other way with a statement allowing the parenthesis be omitted when no arguments are passed.

@samdark
Copy link
Member

samdark commented Jul 17, 2022

I agree with @Crell and @KorvinSzanto on it.

@KorvinSzanto
Copy link
Contributor

@fruitl00p Would you be able to adjust this PR to allow omitting parenthesis when no arguments are passed?

@fruitl00p
Copy link
Author

Very much.. but am on vacay.. feel free to highjack and get this 'sorted' officially

@Crell
Copy link
Collaborator

Crell commented Aug 10, 2022

New PR filed to go the other way.

@samdark samdark closed this Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants