You are here: Re: possible bug (string equality to zero)? « PHP « IT news, forums, messages
Re: possible bug (string equality to zero)?

Posted by "Christopher J. Bottaro" on 08/11/05 20:05

Torgny Bjers wrote:

> 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.

Thanks for the reply,
-- C

> Regards,
> Torgny
>
> Christopher J. Bottaro wrote:
>
>>Is it a bug that ($var == 0) is always true for any string $var?
>>
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация