Re: Booleans compared to strings [message #181348 is a reply to message #181344] |
Mon, 13 May 2013 13:13 |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma:
|
Senior Member |
|
|
On 5/13/2013 8:29 AM, Doug Cassidy wrote:
> So, this is wierd:
>
> $b = true;
> var_dump($b);//boolean true
>
> if(!$b)echo '!$b I wont echo, correctly so<BR>';
> if($b)echo '$b I will echo, correctly so<BR>';
>
> if($b == 'false')echo '$b == I will echo, which is wrong<BR>';
> if($b === 'false')echo '$b === I wont echo, which is correct<BR>';
>
> if($b == 'true')echo '$b == I will echo, which is kinda correct<BR>';
> if($b === 'true')echo '$b === I wont echo, which is very correct<BR>';
>
> Yes, I know that 'true' and 'false' are strings, not bool.
>
> this one:
> if($b == 'false')echo '$b == I will echo, which is wrong<BR>';
>
> I dont see why boolean true is equal to string false in any way.
>
A string comparison returns false only if the string is NULL, is an
empty string ('') or contains a zero ('0'). All other values (including
'false') are true.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
|
|
|