You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PHPCS does exactly what is expected: follow PSR12. PSR12 has no rules about array or list formatting, so PHPCS doesn't enforce any.
And even PER in the current master has no rules about list formatting and has no explicit rule about spacing after a comma for arrays (other than single-line, multi-line).
Surely, it would make sense to have spaces, since 4.7 says:
In the argument list, there MUST NOT be a space before each comma, and there MUST be one space after each comma.
Arguably, these are not function calls, it's arrays and language constructs, so we may need an amendment to explicitly say that the same rule applies there too.
While we don't have specific cases for destructuring, it stands to reason that language constructs like list(...) = would follow the function call rules and [...] = would follow the array declaration rules.
Easy enough to add clarification in a future version but to me there isn't really much ambiguity here and we all know exactly the syntax that would be codified.
Activity
Crell commentedon Jul 1, 2025
I'm pretty sure a space is required after any comma. Sounds like something you should take up with php-cs.
jrfnl commentedon Jul 1, 2025
PHPCS does exactly what is expected: follow PSR12. PSR12 has no rules about array or list formatting, so PHPCS doesn't enforce any.
And even PER in the current
masterhas no rules about list formatting and has no explicit rule about spacing after a comma for arrays (other than single-line, multi-line).Jean85 commentedon Jul 1, 2025
Surely, it would make sense to have spaces, since 4.7 says:
Arguably, these are not function calls, it's arrays and language constructs, so we may need an amendment to explicitly say that the same rule applies there too.
KorvinSzanto commentedon Jul 1, 2025
While we don't have specific cases for destructuring, it stands to reason that language constructs like
list(...) =would follow the function call rules and[...] =would follow the array declaration rules.Easy enough to add clarification in a future version but to me there isn't really much ambiguity here and we all know exactly the syntax that would be codified.
Crell commentedon Jul 1, 2025
Since we're about to tag 3.0, if we want to clarify this further, it sounds like a reasonable 3.1 target.
jrfnl commentedon Jul 1, 2025
Happy to see this addressed/made explicit in PER 3.1.
j-willette commentedon Jul 2, 2025
Agreed, but tools like PHPCS also need to be aware of it.
Similarly, this code doesn't raise any PHPCS error:
$array = ['val1','val2','val3'];Crell commentedon May 2, 2026
Does anyone want to make a PR for this before we close out 3.1? (Which I am late on doing, I know.)