[PSR-12] Closure guidelines for anon classes

67 views
Skip to first unread message

Greg Sherwood

unread,
Apr 23, 2018, 6:53:06 PM4/23/18
to PHP Framework Interoperability Group
Hi,

I'm working on the PSR-12 standard for PHP_CodeSniffer. I have a question about this section:

8. Anonymous Classes
Anonymous Classes MUST follow the same guidelines and principles as closures in the above section.

Almost the entire closure section of PSR-12 is dedicated to argument lists (not a bad thing). The only section of it that isn't contains the following text:

Closures MUST be declared with a space after the function keyword, and a space before and after the use keyword.
The opening brace MUST go on the same line, and the closing brace MUST go on the next line following the body.

The first rule doesn't have anything to do with anon classes and the second is superseded by a more specific rule in the anon classes section.

So my question is: What guidelines and principals should I take from the closure section when writing rules for anon classes?

Thanks

Alexander Makarov

unread,
May 16, 2018, 11:44:43 AM5/16/18
to PHP Framework Interoperability Group
1. The opening brace MUST go on the same line, and the closing brace MUST go on the next line following the body.

Stefano Torresi

unread,
May 16, 2018, 1:22:38 PM5/16/18
to php...@googlegroups.com
TBH making readers to jump to another section that contains different informations is kinda lazy.
Can we just copy paste the relevant indications and do without the reference to the closures?


--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/befdbd91-0c62-4dc6-98cd-caca817a8d5f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Greg Sherwood

unread,
May 16, 2018, 6:31:34 PM5/16/18
to PHP Framework Interoperability Group
Thanks for the clarrification.

I'll echo Stefano's thoughts and say that referring to a previous section is generally helpful when the standard is being heavily modified (you don't want to update 10 places each time), but duplicating those rules once the standard moves to review seems like the right thing to do. From that point on, you don't expect the standard to ever change, so taking the time to duplicate the rules is hopefully a one-off and makes it easier for people like me to review and follow.

In this specific case, the fact that only one sentence (out of the 10 in the closure section) is being referred to, copying that one into the anon class section would make that section much clearer, for me at least.

Greg
Reply all
Reply to author
Forward
0 new messages