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

Propose errata for anonymous classes #1206

Closed
wants to merge 4 commits into from

Conversation

Jean85
Copy link
Member

@Jean85 Jean85 commented Jan 24, 2020

@@ -232,7 +232,7 @@ declare(ticks=1) {

## 4. Classes, Properties, and Methods

The term "class" refers to all classes, interfaces, and traits.
The term "class" refers to all classes, anonymous classes, interfaces, and traits.

This comment was marked as resolved.

Copy link
Contributor

@samdark samdark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GrahamCampbell comment makes sense.

Copy link
Contributor

@KorvinSzanto KorvinSzanto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding the parenthesis to samples makes sense, but only if we also describe why in errata. Adding anonymous classes to section 4 doesn't seem like a helpful change given the confusion.

@Jean85
Copy link
Member Author

Jean85 commented Jan 26, 2020

I've added an errata paragraph, but I'm not to happy with that; any suggestion on how to rephrase that?

@Jean85
Copy link
Member Author

Jean85 commented Jan 27, 2020

I've committed a mix of @samdark & @PowerKiKi suggestions.

@roxblnfk roxblnfk mentioned this pull request Jan 30, 2020
@mvorisek
Copy link

@Jean85 Ready to be merged?

@Jean85
Copy link
Member Author

Jean85 commented Feb 11, 2020

This needs to go through a Core Committee vote to be approved.

@mvorisek
Copy link

@Jean85 Is that already scheduled and when the outcome can be excepted?

@Jean85
Copy link
Member Author

Jean85 commented Apr 14, 2020

It's up to @KorvinSzanto as the editor of the PSR to approve and call the vote on this.

@mbessolov
Copy link

mbessolov commented May 14, 2020

Hello everyone,

While it all looks nice and tidy without any constructor arguments, once they get introduced into the example, it goes haywire.

4.1 Extends and Implements
The extends and implements keywords MUST be declared on the same line as the class name.

Let's see how this plays with constructor arguments present:

$instance = new class($firstConstructorArgument, $secondArgument, $thirdArgument, $andOneMore) extends \Foo implements \HandleableInterface {

or as many of us work with object properties and getters, it aggravates the problem further:

class Sometest {
    public function testSomething()
    {
        $instance = new class($this->getSomething(), $this->somethingElse, $this->andTheThirdProperty(), $this->letsBreakDemeterLawToo()->getX()) extends \Foo implements \HandleableInterface {

While PSR-2 imposes only a soft limit of 120 characters on line length, and there is stricly speaking no problem from the PSR point of view, I think that enforcing extends to be on the same line as new class() makes it barely readable (in the first example the line length is 142 characters, and in the second example it is 192 characters including indentation).

In my opinion a clarification is needed that class in new class() extends is not really "the class name" (they are anonymous classes after all, not having names by definition) and extends and implements keywords may be on the line with the closing parenthesis of a multi-line list of constructor arguments like so:

$instance = new class(
    $foo,
    $bar
) extends \Foo implements \HandleableInterface {

Could this last code snippet be included as an example in addition to/instead of the current one?

@drupol
Copy link
Contributor

drupol commented Jun 12, 2021

What's the status of this ?

@Jean85
Copy link
Member Author

Jean85 commented Jun 14, 2021

There's noone pushing those kind of changes.

The main problem here is that we do not have a way to handle these changes in an iterating way: the language is evolving really fast (enum, union types, matches are just some of the new stuff) and the PSR process is "granitic", since a PSR is supposed to be immutable. We would need a "living document" kind of process, not the simple PSR way as of now, but we're out of ideas for now.

If someone has some idea on how to proceed, it's welcome to discuss that with us, so we can try to define a formal process and make these kind of adjustments easy.

@WinterSilence
Copy link
Contributor

WinterSilence commented Mar 13, 2022

@Jean85 standard immutable, but extendable (for example, RFC standards).
i.e.

  • independent extension: base standard PSR-12 extends by PSR-12.1 (added rules rules anonymous classes), PSR-12.2 (added rules for enum's and annotations) and etc.
  • cumulative extension: base standard PSR-12 extends by PSR-12.1, PSR-12.1 extends by PSR-12.2 and etc.

@Crell
Copy link
Contributor

Crell commented Mar 13, 2022

There is no "extendable with sub-spec" process for PSRs. That's not a thing.

However, we do now have a PER process for evolving standards, and there is a working group for a Coding Standards PER to supplant PSR-12. So that's happening, just not here.

Closing this issue accordingly.

@Crell Crell closed this Mar 13, 2022
@WinterSilence
Copy link
Contributor

@Crell

PER process for evolving standards

where I can read more about it?

@Crell
Copy link
Contributor

Crell commented Mar 13, 2022

@WinterSilence
Copy link
Contributor

@Crell voting to modernize deprecated code looks like strange

jrfnl added a commit to PHPCSStandards/PHPCSExtra that referenced this pull request Jul 22, 2022
Checks the amount of spacing between the `class` keyword and the open parenthesis (if any) for anonymous class declarations.

The expected amount of spacing is configurable and defaults to `0`.

The default value of `0` has been decided upon based on scanning a not insignificant number of codebases and determining the prevailing style used for anonymous classes.
It is also in line with the previously proposed [errata for PSR12](php-fig/fig-standards#1206).

Includes fixer.
Includes unit tests.
Includes documentation.
Includes metrics.
jrfnl added a commit to PHPCSStandards/PHPCSExtra that referenced this pull request Jul 22, 2022
Checks the amount of spacing between the `class` keyword and the open parenthesis (if any) for anonymous class declarations.

The expected amount of spacing is configurable and defaults to `0`.

The default value of `0` has been decided upon based on scanning a not insignificant number of codebases and determining the prevailing style used for anonymous classes.
It is also in line with the previously proposed [errata for PSR12](php-fig/fig-standards#1206).

Includes fixer.
Includes unit tests.
Includes documentation.
Includes metrics.
dingo-d pushed a commit to dingo-d/PHPCSExtra that referenced this pull request May 28, 2023
Checks the amount of spacing between the `class` keyword and the open parenthesis (if any) for anonymous class declarations.

The expected amount of spacing is configurable and defaults to `0`.

The default value of `0` has been decided upon based on scanning a not insignificant number of codebases and determining the prevailing style used for anonymous classes.
It is also in line with the previously proposed [errata for PSR12](php-fig/fig-standards#1206).

Includes fixer.
Includes unit tests.
Includes documentation.
Includes metrics.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
10 participants