Re: if(isset($a)) vs if($a)
| From: | CC Zona | Date: | Sat, 15 Sep 2001 20:20:59 +0000 |
| Subject: | Re: if(isset($a)) vs if($a) | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-67462@lists.php.net to get a copy of this message | ||
In article <1972676115.20010915090000@naverex.kiev.ua>,
ok@naverex.kiev.ua (Andrew Perevodchik) wrote:
> JD> isset checks to see if the $a variable has
> JD> been set, ie, if it exists. if($a) checks for
> JD> the truthood of $a, meaning, if it has a
> JD> non-zero, non-null/empty-string value, then
> JD> its true, else, false.
>
> ... and if it's not set at all it returns a
> warning unless you use "@" :(
Or change the error_reporting level, or turn off display_errors (okay,
technically the warning is still happening in the latter case, but IIRC
that's also true of @--both simply suppress the *reporting* of the report
rather than the *occurance* of the error).
This is why it's best to do multiple checks and choose them carefully. Ex:
if(isset($) and !empty($a) and !$a)
or
if(isset($) and $a===FALSE)
etc.
--
CC