[Solved] Which `if(!isset($foo) OR (isset($foo) AND $foo == $bar))` or `if(!isset($foo) OR $foo == $bar)` is better?


OR, AND, ||, and && all perform short-circuit evaluation. OR and || evaluate their arguments left-to-right until they get to the first truthy value, and then return that. AND and && evaluate their arguments left-to-right until they get to the first falsy value, and return it. In both cases, they don’t evaluate any of the remaining arguments.

So you should use #2, because when !isset($foo) is true it will never evaluate the second expression, so there’s no need to check isset($foo) again.

solved Which `if(!isset($foo) OR (isset($foo) AND $foo == $bar))` or `if(!isset($foo) OR $foo == $bar)` is better?