Fw: [PHP] Question about "if" statement evaluating (0=="string") as TRUE
| From: | Kevin Stone | Date: | Fri, 13 Dec 2002 19:46:54 +0000 |
| Subject: | Fw: [PHP] Question about "if" statement evaluating (0=="string") as TRUE | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-128205@lists.php.net to get a copy of this message | ||
When you define $no, you define it without quotes, so PHP assumes it is a
numeral. What you're asking in your conditional statement is: Does the
numeral 0 equal the integer evaluation of "string". The answer is True.
But when you put $no into quotes you cast it as a string. Now what you're
asking is Does the string "0" equal the string "string". The answer is
False.
-Kevin
----- Original Message -----
From: "Scott Hurring" <scottspam@eac.com>
To: <php-general@lists.php.net>
Sent: Friday, December 13, 2002 12:27 PM
Subject: [PHP] Question about "if" statement evaluating (0=="string") as
TRUE
> Erm... this seems a bit odd to me. I'm using PHPv4.2.2 on Win32
>
> Is that becuase PHP is not properly comparing the numerical value with
> the string value?
>
> <?
> $no = 0;
> if ($no == "string") {
> print "this eval's to TRUE... since when is '0' == 'no' ?";
> }
> if ("$no" == "string") {
> print "whereas this eval's to FALSE, as you'd expect";
> }
> ?>
>
>
>
> --
> Scott Hurring
> Systems Programmer
> EAC Corporation
> scott (*) eac.com
> --
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>