At 03:06 PM 2/6/2002 -0500, 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?

The problem with using (!$_POST['var']) as an expression is that you are 
asking the parser to evaluate the expression as a boolean.  If 
$_POST['var'] isn't a boolean (and it won't be, because unless I'm mistaken 
all POST or GET variables are treated as strings unless you cast them) then 
the parser does an implicit cast to boolean while evaluating your expression.

This is fine for most cases, but let's say that $_POST['var'] *is* set to 
either an empty string ("") or a string containing zero ("0").  Your test 
will fail, because both of these are evaluated as FALSE when cast as a boolean.

That's the reason that isset() is a little more general purpose.  If you 
aren't worried about missing an empty string or a string containing "0" 
then you can continue to use the method you have been using.

For more info, see this:

<http://www.php.net/manual/en/language.types.boolean.php#language.types.boolean.casting>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to