I have always thought that if I want to check if a variable exists and has a certain value I have to use two if
conditions:
if(isset($x)){
if($x->age==5){}
}
But I realized its also possible to do it in one line this way:
if(isset($x) && ($x->age==5)){}
Can someone tell me why the second variation will not result in an error if $x
is null. Given that $x
is null and doesn't have the property age
? Would it be trying to access a property that doesn't exist?
$x=null;