-
Notifications
You must be signed in to change notification settings - Fork 26
Multi-line arrays / Trailing commas in (multi-line) arrays #14
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
Comments
I know at least some coding standards mandate the trailing comma if multi-lining an array. If we do something here, it should apply to all multi-line-with-comma situations. Eg, function calls, function definitions, arrays, etc. |
There are objective advantages always having a comma:
I think it may sense to at least softly suggest it in form of SHOULD. |
I wouldn't say that adding trailing commas contributes to readability but I would be okay with adding a "SHOULD" with the added info of it being helpful when diffing code changes. I don't think SHOULD's or optional requirements in general benefit this spec much since they can't really be enforced with tools without custom configuration, in this case where it is beneficial in many cases I think it's worth mentioning. I wonder if there'd be a better way we could organize these sorts of soft optional requirements where at least consistency is a MUST. Something like:
But this might make things more painful than SHOULDs would on their own. |
Possible PR: #18 |
Yep #18 merged and specifies when a trailing comma must or must not be used so I think this is settled. |
PHP supports trailing commas in arrays since 7.2. As of now the existing formatting standards of PHP-FIG do not specify whether or not (or when) trailing commas in Arrays are acceptable or required. More generally the formatting of multi-line arrays is left unspecified, whereas for other constructs it is clearly specified how they need to be split across multiple lines.
This is related to #3, since PHP 7.3+ introduces additional constructs where trailing commas are allowed and PHP 8.0 introduces named parameters which are syntactically very close to an associative array literal.
The text was updated successfully, but these errors were encountered: