declare must follow the rule for assignment operator#992
declare must follow the rule for assignment operator#992PowerKiKi wants to merge 1 commit intophp-fig:masterfrom
declare must follow the rule for assignment operator#992Conversation
`declare` statements must follow the rule for assignment operator which dictates to have exactly 1 space around the operator. There was no reason to make it an exception. It made the rule harder to explain, and harder to remember. By keeping a single rule for all cases everything is made simpler.
Jean85
left a comment
There was a problem hiding this comment.
Since we're going this way, shouldn't we go "follow the common rule" all the way?
| ~~~ | ||
|
|
||
| Declare statements MUST contain no spaces and MUST be exactly `declare(strict_types=1)` | ||
| Declare statements MUST be exactly `declare(strict_types = 1)` |
There was a problem hiding this comment.
Shouldn't we make the semi-colon mandatory, so it follows the common rule about that too? At that point, this row can be changed into something like
decladefollows the same rules as the rest of the code: MUST have one space around the=operator and it MUST terminate with a semicolon
There was a problem hiding this comment.
I believe the mention of semicolon is only for cases like <?php declare(strict_types = 1) ?>. As shown in the example starting with "When wishing to declare...". Because otherwise it would be a parse error AFAIK. I don't think the case of semicolon before ?> end tag is mentioned anywhere else. Maybe it should be removed from here and addressed separately ?
|
This also relates to #984 |
|
Does this mean that PSR-12 is going to ignore the ~90% votes for not using spaces? |
|
We already agreed not to do this and it's in review now so it cannot be modified without a push back to draft. |
|
While I understand that ~90% voters prefer no spaces for declare() as mentioned by @nicwortel, I think that it should be re-reviewed and better argumented to voters in according with @PowerKiKi when he mentions that PSR suggests a space between operators in assignments. Actually, the Review of Extended Coding Style Guide in 6. Operators declares that "all binary and ternary (but not unary) operators MUST be preceded and followed by at least one space. This includes all arithmetic, comparison, assignment, bitwise, logical (excluding ! which is unary), string concatenation, type operators, trait operators (insteadof and as), and the single pipe operator (e.g. ExceptionType1 | ExceptionType2 $e). Other operators are left undefined". It was mentioned on mailing by @PowerKiKi but not was replied. -- I have sent to mailing: https://groups.google.com/forum/#!topic/php-fig/ZJTLn-aLSq4 |
|
With PSR-12 being moved back to DRAFT status (see https://groups.google.com/forum/#!topic/php-fig/1TBEvCIHFv0), can this be reopened and reconsidered, or should this be brought up in the mailing list first? |
|
I cannot re-open my PR, but I'll gladly submit a new one with the same patch if the PSR guys agree to reconsider the situation. |
|
Hi @PowerKiKi, we recently discussed this, and come to the conclusion that the common usage is without spaces, since it's been like this even in the orignal RFC that introduced the |
|
@Jean85 so I guess that the "common usage" is counterintuitive here, once that it is definitively an assignment. The RFC code is not a code style reference, it just should exemplify how a new feature should works. In the same page it put brackets on same line from class definition, so it even respect PSR. I really don't see any reason to avoid spaces in |
|
@rentalhost |
|
@rob006 Actually About I just do not understand "why" everything should be spaced except that one. I don't think that "the common usage" should be a valid argument here, I think that it deserves a logic definition that everyone could understand the reason without come to here to understand "the why". |
Sorry, but this is ridiculous. Then we can say that variable is a constant, but with possibility to overwrite after initialization. And
I could not disagree more. This is only about "what it is". And your arguments like "it acts like constant" are very good reason to use different rules for |
No, it should sounds like: assignments could/must occur in constants, variables or declarations.
Okay, it could be about "what it is", and it is an assignment (I mean the internal part like
It doesn't make any sense. |
|
@rentalhost you're mixing up a lot of names...
Nope, those are language constructs, and we are going to cover them explicitly in an other addition to the PSR. Currently we have #1021 pending, but we will probably change that a little.
That's not what the PSRs says, and that's not what happens with a compiler directive like |
declarestatements must follow the rule for assignment operator which dictates to have exactly 1 space around the operator.There was no reason to make it an exception. It made the rule harder to explain, and harder to remember. By keeping a single rule for all cases everything is made simpler.