FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Booleans compared to strings
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Booleans compared to strings [message #181356 is a reply to message #181348] Mon, 13 May 2013 15:22 Go to previous messageGo to previous message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma:
Senior Member
Jerry Stuckle wrote:

> 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.

The reason for this is type juggling, not “string comparison”.

What you might have meant is how a string value in a type-converting
conditional expression is evaluated (like that of “if ($string)” or
“($string) ? … : …”), where type juggling is performed as well.


PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Security risks allowing users to upload a css file?
Next Topic: mkdir no such file or directory
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Dec 01 00:05:45 GMT 2024

Total time taken to generate the page: 0.03537 seconds