I'm trying use the PSR conventions in all my projects, but today I view some code of my co-worker and I disagree.

if ($cond == 1 AND $cond == 2) {
    // to-do

For me, the correct is:

if (($cond == 1) AND ($cond == 2)) {
    // to-do

What is the correct use of the PSR?


Per the PHP Framework Interop Group's PSR definitions, this particular case is not addressed:


I don't see any guidance on the usage of logical operators as "words", i.e. "and", "or", "not", etc versus symbols, i.e. "&&", "||", "!" within boolean expressions.

If I were to follow precedence and make my own extension of the above PSR reference, I could only conclude that the word "AND" should be written as "and" given the preference for lower case when using reserved words...

  • Both of the examples given use AND (which I also think should be lowercased for PSR2); the difference between them is the redundant parentheses. AFAICT that's not a violation of PSR2 either, but I would say it's still bad coding style. If you go the route that PSR2 letting you have one pair of redundant parentheses means it's a good idea, why not have two pairs or ten? Just because PSR2 lets you doesn't mean it's a good idea. – mmitchell Feb 16 '17 at 18:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.