Re: Booleans compared to strings [message #181355 is a reply to message #181344] |
Mon, 13 May 2013 15:18 |
Thomas 'PointedEars'
Messages: 701 Registered: October 2010
Karma:
|
Senior Member |
|
|
Doug Cassidy wrote:
> So, this is wierd:
“Weird” is a subjective assessment.
> $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.
It's not a bug, it's a feature. See
<http://php.net/manual/en/language.types.type-juggling.php> for details.
By contrast to “==” and “!=”, “===” and “!==” do not do type juggling.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
|
|
|