Re: !isset ??
| From: | CC Zona | Date: | Wed, 06 Feb 2002 20:28:07 +0000 |
| Subject: | Re: !isset ?? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-83749@lists.php.net to get a copy of this message | ||
In article <0C6A07A3-1B3D-11D6-A011-0050E4857868@hhbrown.com>,
pricee@hhbrown.com (Erik Price) wrote:
> Pretty confusing. Can anyone shed some light on whether or not there is
> a final definite way to do this? I've used (!($_POST['var'])) with no
> problems in the past, but does good coding style suggest that I use
> (!isset($_POST['var'])) now?
"!$somevar" != "!isset($somevar)"
isset() evaluates as true only if the variable (or array index) exists.
PHP's loose typing means that !$somevar evalutes as true if the variable is
null, if it has an (integer, float, or string) value of zero, if it's an
empty string, or if it is set to boolean false. Or if the variable/index
does not exist.
Both methods have their place (though for tests of the latter, I prefer
empty()). The important part is understanding the implications of a method
when you use it, so that your code isn't wrongly relying on !$somevar to
mean the variable isn't set; it may well have been set, to a meaningful
value which just happens to evaluate to false.
--
CC