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:
https://www.php-fig.org/psr/psr-2/
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…
2