In PHP (and many other languages), logical operators use a short circuit rating . This means that if the result of an expression is already determined after evaluating part of the expression, then the rest will no longer be evaluated.
In your example, isset($var) returns false. Since the && operator is defined so that it is true only if all of its subexpressions are true, this means that it cannot be true if the left subexpression is false. Therefore, the right subexpression will not be evaluated (and does not cause an error).
Evaluating short circuits is very useful because you can combine a subexpression that will lead to a runtime error with another that ensures that this does not happen. An example is the example you gave. Other languages ββoften use a similar construct for zero-save constructs, for example. if (foo != null && foo.bar == 1) in Java or C # - foo.bar will throw an exception if foo was null, but the merits of short circuit evaluation ensure that it will never be evaluated.
source share