Re: Question about "if" statement evaluating (0=="string")as TRUE
| From: | Scott Hurring | Date: | Fri, 13 Dec 2002 19:46:11 +0000 |
| Subject: | Re: Question about "if" statement evaluating (0=="string")as TRUE | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-134183@lists.php.net to get a copy of this message | ||
I figured it was along those lines... i know that perl also caught
me a few times becuase perl differentiates between "==" and "eq"
for numerical or string comparisions.
I'll probaly end up using the "===", becuase i've got a severe
aversion to using functions for comparisions. :-)
--
Scott Hurring
Systems Programmer
EAC Corporation
scott (*) eac.com
--
"Marco Tabini" <marcot@inicode.com> wrote in message
news:1039808068.2738.295.camel@localhost.localdomain...
> I think this is happening because you're comparing apples to oranges.
> Your first comparison causes an integer to be compared to a string.
> Because the string "string" evaluates to the integer value 0, the
> comparison succeeds. The manual recommends the use of the identical
> comparison operator (===) instead, or--better yet--the strcmp() function
> when comparing two strings.
>
> Cheers,
>
>
> Marco
>
> --
> ------------
> php|architect - The magazine for PHP Professionals
> The monthly worldwide magazine dedicated to PHP programmers
>
> Come visit us at http://www.phparch.com!
>