php - Check what part of an IF statement is false/true when using logical operators
one text
Solution:
There's no good way. In the case you describe PHP will not evaluate all the content of the parentheses.
In case empty($a) is true, php will not evaluate empty($b). Because the OR will be true anyway.
You can do the following test:
$a = 1; $b = 0;
if($a || $c) print "2";
This should be show PHP Notice: Undefined variable: c..
But instead it print 2
The best is to evaluate separately
try{
if(empty($a)) throw new \Exception('$a is empty');
if(empty($b)) throw new \Exception('$b is empty');
} catch (\Exception $e) {
print($e->getMessage());
}
Source