Hi all,
The most recent version of PHP_CodeSniffer (2.2) contained a change to properly enforce and fix "There MUST NOT be a space after the opening parenthesis" [1] for PSR-2 control structures.
I've had someone question this change [2] because there is confusion over the term "space" and if that rule also bans newlines after the opening parenthesis. PHP_CodeSniffer currently catches both spaces and newlines and treats them the same way.
This is made a bit more unclear to me due to the example code provided in PSR-2, specifically for an IF statement in this case [3], and comments made on some PSR-2 issues [4] [5].
Obviously, this code is valid:
1: if ($expr1 && $expr1) {
2: }
Although PSR-2 doesn't specifically mention multi-line IF statements, this also follows all the rules:
1: if ($expr1
2: && $expr1) {
3: echo 'foo';
4: }
But this technically might not be valid, because there is a newline before the closing parenthesis, although this is how I see most people writing multi-line IFs:
1: if ($expr1
2: && $expr1
3: ) {
4: echo 'foo';
5: }
If we assume that the newline is not actually a space, then this can also be valid (which is the original query):
1: if (
2: $expr1
3: && $expr1
4: ) {
5: echo 'foo';
6: }
But then is this also valid code?:
1: if (
2:
3: $expr1
4: && $expr1
5:
6: ) {
7: echo 'foo';
8: }
Sorry for all the example code, but the question ends up boiling down to: Throughout PSR-2, does the word "space" mean a single space character or does it include any whitespace (e.g., space, tab, newline)?
Thanks
Greg