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 #181370 is a reply to message #181355] Mon, 13 May 2013 22:21 Go to previous message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma:
Senior Member
On 13/05/13 16:18, Thomas 'PointedEars' Lahn wrote:
> Doug Cassidy wrote:
>
>> So, this is wierd:
> “Weird” is a subjective assessment.
even when spelt* correctly

* that is a valid and in many ways more correct version of 'spelled'

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

Thats the trouble with a loosely typed language that trys to second
guess what you mean. You cant second guess total iditiots. And ometimes
you may fail to correctly guess wise men too.

ISTR the bug i found where two browsers gave entirely different results
in javascript was more or less of the < if ('1' == 1) > variety. One
browser said true, the other said false...and when I looked at the
javsacript spec there seemd to be no casting rule defined for conditionals.

And I had to spend a day trying to force an explicit cast so the same
code produced the same result in firefox as IE6.


>
> PointedEars


--
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to lead are elected by the least capable of producing, and where the members of society least likely to sustain themselves or succeed, are rewarded with goods and services paid for by the confiscated wealth of a diminishing number of producers.
[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: Sat Nov 30 23:29:16 GMT 2024

Total time taken to generate the page: 0.04260 seconds