Basically
Is this:
<?PHP if (false && crazyFunction()) : ?>
The same as:
<?PHP if (false) : ?>
<?PHP if (crazyFunction()) : ?>
If FALSE is evaluated in the first example will it still continue to evaluate "crazyFunction"?
Basically
Is this:
<?PHP if (false && crazyFunction()) : ?>
The same as:
<?PHP if (false) : ?>
<?PHP if (crazyFunction()) : ?>
If FALSE is evaluated in the first example will it still continue to evaluate "crazyFunction"?
The &&
operator is a shotcircuit operator, which means that it will stop as soon as it knows the outcome is going to be false.
This means that if the left part evaluates to false it stops and returns false. crazyFunction()
will never be called in this example.
As soon as the value of boolean expression is known, it is no more executed.
Please note this (deprecated) example in old-fashioned mysql connections:
$db=mysql_connect_db('...') or die('Database error');
If after first part mysql_connect
returned something that is not FALSE
, 0, NULL
etc., it does not execute this die()
.
(Regardless if this is or not correct to use mysql_*
functions)