2

Is this 2 statements or 1?

if ($a == "A" && $b == "B") { // do something }

How do I use two statements if I want to follow PSR standards? Should I use multiple if's? Like if inside an if?

sectus
  • 15,605
  • 5
  • 55
  • 97
  • 1
    I'd just do what feels right for you, as long as you remain consistent to your own rules. The PSR "standards" are a load of horse crap anyway. – GordonM Aug 07 '14 at 08:10
  • 1
    The things inside the parens are expressions. Within the curlys you have statements. The `if` itself is a control construct. More importantly you shouldn't blindly follow coding styles, but apply what makes sense, and deviate when necessary to aid readability. – mario Aug 07 '14 at 08:11
  • Two statements per line would be `foo(); bar();`. – deceze Aug 07 '14 at 08:15

1 Answers1

1

It simply should look like this:

if ($a == "A" && $b == "B") {


}

You don't need to create multiple ifs

If you have longer conditions you could use such syntax:

<?php

if ($a == "A"
    && $b == "B"
) {


}

Both of them were tested in PhpStorm when code style is set to PSR

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
  • 1
    @LovebRazil Yes, this is one statement. Multiple would be `$a = 5; $b = 10;` and it is not PSR compliant because these are 2 statements in one line – Marcin Nabiałek Aug 07 '14 at 08:19