PHP: use isset in ternary or not? -


say have function:

function foo($var = null) {       return $var ? 'good' : 'bad';   // return (isset($var) && !empty($var)) ? 'good' : 'bad'; } 

this function works expected , should syntaticaly correct, $var default value set , there reason use isset() , empty php function?

p.s: good acceptable when $var not null false or ''

as said in comments, if test, php procedes type inference.

so there values in $var echo bad if they're not null.

for more precise answer, should check php type comparison tables : have exemples of differences between if($x), isset(), is_null() , empty() depending on value of variable test.


Comments