Zero is equal to any string?
| From: | Simon Garner | Date: | Sun, 03 Sep 2000 06:20:34 +0000 |
| Subject: | Zero is equal to any string? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-14966@lists.php.net to get a copy of this message | ||
Hi,
I encountered some rather baffling behaviour today while working on a page,
and eventually narrowed the problem down to the following:
<?
if (0 == "some string")
{
echo "They're equal!";
}
?>
This will echo "They're equal!", which makes no sense to me. Why should 0 be
equal to any string? 0 should surely be equal only to the empty string and
the boolean value false.
Note that (1 == "some string") returns false, and so does (0 === "some
string") as expected. I've tested the (0 == "some string") under 4.0.2,
4.0.1pl2 and 3.0.16 always with the same results.
Is this a bug or a "feature" of the language?
Cheers,
Simon Garner