Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #9300

Re: Booleans compared to strings

Message-ID <22836064.xOeTbpBGaj@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2013-05-13 17:18 +0200
Subject Re: Booleans compared to strings
Newsgroups comp.lang.php
References <b292b42b-16ed-40bc-b005-79970a9e6362@googlegroups.com>

Show all headers | View raw


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

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Booleans compared to strings Doug Cassidy <doug@dougcassidy.com> - 2013-05-13 05:29 -0700
  Re: Booleans compared to strings Jerry Stuckle <jstucklex@attglobal.net> - 2013-05-13 09:13 -0400
    Re: Booleans compared to strings Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-13 17:22 +0200
    Re: Booleans compared to strings Doug Cassidy <doug@dougcassidy.com> - 2013-05-13 13:24 -0700
      Re: Booleans compared to strings "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2013-05-13 23:22 +0200
        Re: Booleans compared to strings Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-13 23:46 +0200
          Re: Booleans compared to strings The Natural Philosopher <tnp@invalid.invalid> - 2013-05-13 23:28 +0100
            Re: Booleans compared to strings Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-14 00:41 +0200
            Re: Booleans compared to strings Jerry Stuckle <jstucklex@attglobal.net> - 2013-05-13 18:56 -0400
            Re: Booleans compared to strings "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2013-05-14 21:36 +0200
              Re: Booleans compared to strings The Natural Philosopher <tnp@invalid.invalid> - 2013-05-14 21:17 +0100
                Re: Booleans compared to strings "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2013-05-15 21:34 +0200
        Re: Booleans compared to strings The Natural Philosopher <tnp@invalid.invalid> - 2013-05-13 23:26 +0100
          Re: Booleans compared to strings Jerry Stuckle <jstucklex@attglobal.net> - 2013-05-13 18:57 -0400
  Re: Booleans compared to strings Robert Heller <heller@deepsoft.com> - 2013-05-13 08:57 -0500
    Re: Booleans compared to strings Doug Cassidy <doug@dougcassidy.com> - 2013-05-13 13:23 -0700
  Re: Booleans compared to strings Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-13 17:18 +0200
    Re: Booleans compared to strings The Natural Philosopher <tnp@invalid.invalid> - 2013-05-13 23:21 +0100

csiph-web