Re: Isset
| From: | Michael Sweeney | Date: | Fri, 21 Mar 2003 19:08:36 +0000 |
| Subject: | Re: Isset | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-140624@lists.php.net to get a copy of this message | ||
It depends on what you're trying to test.
If you want to find out if a variable is explicitly set to an empty
string, then isset() is not your answer. If you want find out if a
variable exists or is set to a non-null value, isset() will work.
However, it is not always going to give you the results you want in
checking submitted variables from a web page. For instance if an input
variable is set in the form with a value of "", isset() on that variable
will return true, even if it is empty. So if you testing for a value
being submitted, you'll get erroneous results. I've found empty() to be
a better test in many cases than isset(), but it depends on what you're
trying to test.
..michael..
On Fri, 2003-03-21 at 11:09, Liam Gibbs wrote:
> Responding to myself:
>
> <<Is isset() better than $ != ""?
>
> Often, I may have a 0 as values. While $ != "" doesn't recognize 0s (as in,
> that if would be false), isset() seems to work. Should I change all my $ !=
> "" to isset()s, or are there other factors I should check?>>
>
> Conversely, what about empty(). Is that a better test for if a value could
> be 0 or 1 or 2 or ABC?
--
Michael Sweeney <sweeney@verisity.com>
Verisity Design, Inc