Re: $VAR = 0 != false
| From: | Andre Fadel | Date: | Tue, 08 Aug 2000 02:08:34 +0000 |
| Subject: | Re: $VAR = 0 != false | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-10565@lists.php.net to get a copy of this message | ||
Description
int empty(mixed var);
Returns false if var is set and has a non-empty or non-zero value; true
otherwise.
That means that if it's zero i will return true. You're using not (!) so
it returns false.
Stick with isset(), which is suitable for what you need.
--
André Fadel
fadel@fee.unicamp.br
Hoje E Sempre GUARANI!
On Mon, 7 Aug 2000, Brian T. Allen wrote:
> Hi *,
>
> I have an ecommerce site where the shopping cart supports options for items.
>
> One of the items has an option that is stored in the database as 0 (zero). It doesn't
> mean false, it means that an option was selected, and the option was 0.
>
> If I echo out the variable, you get "0" echoed out.
>
> $VAR = "0";
> echo $VAR;
>
> You get what you would expect.
>
> But, if you verify the variable exists first:
>
> if($VAR){
> echo $VAR;
> }
>
> You get nothing, even though the variable is set. It is set to zero, granted, but it is set!
>
> I can understand that in some types of tests you want 0 to be synonimous with false, but here I
> am only testing if the variable is set to a value, be it false, 0, or something else.
>
> I just tested, and isset() works like I think it should (I am NOT the source of all truth and
> knowledge, just trying to make this make sense), but !empty() does not:
>
> if(!empty($VAR)){
> echo $VAR;
> }
>
> even though $VAR isn't empty.
>
> Thoughts, comments, flames?
>
> Thanks,
> Brian
>
>