Re: Re: possible bug (string equality to zero)?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Using === should work.   This is most likely because, if I remember correctly, when you compare a string to a integer, it essentially does an intval(string).  If the string contains no numbers, you end up with nothing.. or zero.

It definitely isn't a bug and definitely has to do with type conversion though.  the triple equalsign deal should work since it forces PHP not to convert types.

-TG

= = = Original message = = =

>> No, Christopher, that is not a bug. As long as the var is empty, and if
>> you try to compare with 0, or false, it will report true in the
>> comparison because the variable does not contain anything, which will
>> mean false for a boolean and 0 for a variable. If you are attempting to
>> discover if a string contains data, use empty() instead. You can also
>> check if the string is null or actual zero (0).
>
> But the var isn't empty.
>
> $a[] = 'blah';
> $a[] = 'blah';
> $a['assoc'] = 'array';
> foreach ($a as $k => $v)
>  if ($k == 'assoc')
>    # do something
>
> The 'if' statement is incorrectly executing when $k is 0.  I find it strange
> that 0 == any string.  The way I see it, 0 is false.  false == 'a string'
> should not be true.
>

You might try "===" instead of "==" to get type checking as well...


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux