0

Can I use if statement like:

if (!true) {
    return false
}

Or something like this:

if (! true) {
    return false
}
Dmitry Leiko
  • 3,970
  • 3
  • 25
  • 42
  • 2
    Pipe your code through `phpcs` with PSR-12 used as the standard and check the output. – Matt Komarnicki Nov 02 '20 at 11:29
  • What does PSR-12 say? What do the examples look like? In any case, you don't have to follow PSR-12 at all if you don't want to. – Ulrich Eckhardt Nov 02 '20 at 11:32
  • What does `true` represent in your question? Is it a single variable or could it be an expression? The answer may differ depending upon that – Martin Nov 02 '20 at 11:34

1 Answers1

3

According to PSR example all conditions in if clauses have no space before or after the expressions. In your case then

if (!true) {
    return false;
}

would be a case. Remember that with short expressions you can always use ternary operator and if you have complex condition to be checked, consider to put it into variable.

PatNowak
  • 5,721
  • 1
  • 25
  • 31
  • 1
    Is this classifying the ! as being a unary operator and therefore no space, although PSR-12 only specifically mentions `++` and `--`. – Nigel Ren Nov 02 '20 at 11:39