Home > Archive > PHP DB > May 2007 > weird comparsion
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| Hello,
Why does anything compared to 0 return true?
I know it might seem to be a bit off-topic, but for me it is important
for detecting if NULL value in table has been changed (for example NULL
is changed to 0).
if ("foo"==0) echo("foo equals to 0");
OKi98
| |
| itoctopus 2007-05-04, 7:57 am |
| You have to use the type equality
=== (3 equals), otherwise, what the comparision does it that it will compare
the value of "foo" as a number (which is 0) to 0.
Note that there are php functions, such as strpos, who can lead to serious
flaws in your program if you use the type equality.
strpos returns 0 if the position of the string is 0 in the other string,
however, it returns FALSE if it is not.
Hope that helps,
--
itoctopus - http://www.itoctopus.com
"OKi98" <oki98@centrum.cz> wrote in message
news:4639C29C.50202@centrum.cz...
> Hello,
>
> Why does anything compared to 0 return true?
>
> I know it might seem to be a bit off-topic, but for me it is important for
> detecting if NULL value in table has been changed (for example NULL is
> changed to 0).
>
> if ("foo"==0) echo("foo equals to 0");
>
> OKi98
|
|
|
|
|