Search code examples
phpsemantics

Using '&&' instead of 'if' for single instructions


I'd like to know if there are any problems with doing this:

($this->debug)
    && print "We're debugging right now";

instead of this:

if ($this->debug)
    print "We're debugging right now";

To me, it's just a style thing. Does it do exactly the same thing?


Solution

  • Please don't. This is horribly unreadable. And it starts innocently enough, soon other "clever" developers would come and invent more "clever" ways of using this && operator to avoid those "horrible" ifs.

    Please... Don't.


    Functionally, yes, they will work the same.