Re: Re: PHP 4.0 Bug #7478 Updated: empty() function does not work as expected
| From: | (Heiner Steven) | Date: | Thu, 26 Oct 2000 15:12:14 +0000 |
| Subject: | Re: Re: PHP 4.0 Bug #7478 Updated: empty() function does not work as expected | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-36076@lists.php.net to get a copy of this message | ||
joey wrote:
> Here's what the manual has to say:
> Returns false if var is set and has a non-empty or non-zero
> value; true otherwise.
> The only bug here is in your idea of what empty() means.
Well, that was obvious in the first place ;-)
PHP takes the Perl concept of assuming that after
$var = "0"
the variable is empty. In this context, empty() has no benefit, because
it's functionality can be achived just by using "if ( !$var )".
I showed a way of giving empty() an improved functionality that would
provide PHP programmers with an easy way to determine an empty string
(instead of a "string who's value is FALSE").
Well, thank you for your immediate feedback on this problem.
Heiner
On Thu, 26 Oct 2000, Heiner Steven wrote the following to joey@joeysmith.com :
> On Thu, 26 Oct 2000, Heiner Steven wrote the following to php-dev@lists.php...:
>
> > The basic fact is, that I would like to be able
> > to get three kind of information for a variable:
> >
> > 1. Does a variable exist? -> isset()
> > 2. Is the variable empty? -> empty ()
> > 3. Has the variable's content a truth value? -> ($var)
> >
> > The second case does not work as expected.
> >
>
> > Can you give an example of somethat that is true for 1 & 3 but
> > not 2?
>
> That misses the point: 2 and 3 have identical results, but
>
> empty ("0")
>
> just should not be TRUE: the string "0" is not empty. It contains exactly
> one character: '0' or ASCII 48.
>
> I would expect to find
>
> empty ("")
>
> to be true.
>
>
> Heiner
----- End Included Message -----