[PHP-DEV] Re: empty() II From: Jan Legenhausen (jan <email protected>)
Date: 05/30/98

Zeev Suraski wrote:
>
> At 16:08 30/05/98 +0200, Jan Legenhausen wrote:
> >I just discovered that empty($test) also says "TRUE" for $test=0.
> >
> >Now i think i begin to understand what empty() is good for... :)
> >It gives TRUE if the given value for that given type corresponds to the
> >value of 0. Unset variables are supposed to also have a value of 0. A
> >string value of "0" isn't considered as empty - but "if ($test)" results
> >in FALSE (is this intentional?).
> >For me, this all makes things not _so_ easy, if all i want to ensure is
> >to catch POSTed form vars and distinguish between fields not filled and
> >fields filled with "0"...
>
> empty() was designed *exactly* for this. Basically, when you want to
> ensure that form fields were properly sent, and that they were filled with
> something - you check that they're not empty(). If empty() returns true -
false?!
> it means they're both set, *and* something was typed into them.
> The definition of empty() on non-strings isn't all that interesting.

You are right, after the fix of empty("0") _not_ to be true, this can be
used. I somewhere lost the oversight... ;-)

>
> By the way, yes, if ("0") => false is intentional.
This broke all my scripts made with versions < PHP3RC5... which means,
this changed in RC5... :-/
In fact, i initiated a little panic, as i wanted to last-minute-switch
to RC5 for a bigger project, having the nice error_log() working. This
was the day before the launch - and suddenly all did behave very
strange... I reverted back to RC4 for now.
Since empty() now is usable, i'll upgrade again next days...

yours, Jan

>
> Zeev
> --
> Zeev Suraski <zeev <email protected>>
> For a PGP public key, finger bourbon <email protected>