Re: Newbie question about good coding practice [isset]

From: Date: Sat, 05 Jun 2004 19:24:26 +0000
Subject: Re: Newbie question about good coding practice [isset]
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-187705@lists.php.net to get a copy of this message
When $var is 0? <? $var = 0; // Output: $var: $var not exists if ( $var )
    echo '$var: $var exists<br>';
else
    echo '$var: $var not exists<br>';
// Output: isset(): var exists if ( isset($var) )
    echo 'isset(): $var exists<br>';
else
    echo 'isset(): $var not exists<br>';
?> Larry E . Ullman wrote:
if($var) do something; verses if(isset($var)) do something; The simple form if($var) seems to work fine and I see it in code often. Is there a good reason for using isset?
Yes, if you don't use isset(), you may see notices (errors) if the variable is not set. This depends upon the error reporting settings of the server. However, if you use isset() you won't see notices regardless. Larry


« previous php.general (#187705) next »