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
Switch to threaded view of this topic Create a new topic Submit Reply
Booleans compared to strings [message #181344] Mon, 13 May 2013 12:29 Go to next message
doug[1] is currently offline  doug[1]
Messages: 10
Registered: March 2013
Karma: 0
Junior Member
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.
Re: Booleans compared to strings [message #181348 is a reply to message #181344] Mon, 13 May 2013 13:13 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
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
==================
Re: Booleans compared to strings [message #181349 is a reply to message #181344] Mon, 13 May 2013 13:57 Go to previous messageGo to next message
Robert Heller is currently offline  Robert Heller
Messages: 60
Registered: December 2010
Karma: 0
Member
At Mon, 13 May 2013 05:29:05 -0700 (PDT) Doug Cassidy <doug(at)dougcassidy(dot)com> 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.

Well, duh!

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

Any non empty value (including a non empty string) is true, therefore "$b ==
'false'" evaluates to true. Live with it.

PHP is using the *C* convention with respect to booleans. 0 is false, and any
non-zero value is true. A NULL pointer (eg an empty string) is effectively the
same as a numeric value of 0, and is thus false also. Any non-NULL pointer (eg
any object, array, or string) is effectively the same as a non 0 numeric
value, and is thus true.

Why in the world are you comparing booleans to strings? If this is a
string-based parameter setting, you should be just comparing the strings and
not be using booleans at all. Or you should not be using string-based
parameter settings for boolean parameters. Or you need to write a suitable
checking function that does an 'intellegent' type casting that suits the use
case you are handling. Something like:

function string_to_boolean($string) {
switch ($string) {
case 'true':
case 'yes':
case '1':
case 1:
case true:
return true;
case 'false':
case 'no':
case '0':
case 0:
case false:
return false;
default:
if (empty($string)) {
return false;
} else {
return true;
}
}
}

Then:

if ($b == string_to_boolean('false')) echo '$b == string_to_boolean(\'false\') I wont echo, which is correct<BR>';

Will behave as expected.


--
Robert Heller -- 978-544-6933 / heller(at)deepsoft(dot)com
Deepwoods Software -- http://www.deepsoft.com/
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments
Re: Booleans compared to strings [message #181355 is a reply to message #181344] Mon, 13 May 2013 15:18 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
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
Re: Booleans compared to strings [message #181356 is a reply to message #181348] Mon, 13 May 2013 15:22 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
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
Re: Booleans compared to strings [message #181365 is a reply to message #181349] Mon, 13 May 2013 20:23 Go to previous messageGo to next message
doug[1] is currently offline  doug[1]
Messages: 10
Registered: March 2013
Karma: 0
Junior Member
On Monday, May 13, 2013 6:57:10 AM UTC-7, Robert Heller wrote:

> Why in the world are you comparing booleans to strings?

Dealing with mistakenly written legacy code.
Re: Booleans compared to strings [message #181366 is a reply to message #181348] Mon, 13 May 2013 20:24 Go to previous messageGo to next message
doug[1] is currently offline  doug[1]
Messages: 10
Registered: March 2013
Karma: 0
Junior Member
On Monday, May 13, 2013 6:13:11 AM UTC-7, Jerry Stuckle wrote:
> On 5/13/2013 8:29 AM, Doug Cassidy wrote:

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

got it, thanks
Re: Booleans compared to strings [message #181368 is a reply to message #181366] Mon, 13 May 2013 21:22 Go to previous messageGo to next message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
Am 13.05.2013 22:24, schrieb Doug Cassidy:
> On Monday, May 13, 2013 6:13:11 AM UTC-7, Jerry Stuckle wrote:
>> On 5/13/2013 8:29 AM, Doug Cassidy wrote:
>
>>> 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.
>
> got it, thanks
>

My favourite link to comparison in PHP is
http://www.php.net/manual/en/types.comparisons.php
where you have also the "if ($x)" results.

Highly recommended.

/Str.
Re: Booleans compared to strings [message #181369 is a reply to message #181368] Mon, 13 May 2013 21:46 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
M. Strobel wrote:

> Am 13.05.2013 22:24, schrieb Doug Cassidy:
>> On Monday, May 13, 2013 6:13:11 AM UTC-7, Jerry Stuckle wrote:
>>> On 5/13/2013 8:29 AM, Doug Cassidy wrote:
>>>> 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.
>> got it, thanks
>
> My favourite link to comparison in PHP is
> http://www.php.net/manual/en/types.comparisons.php
> where you have also the "if ($x)" results.
>
> Highly recommended.

Slighty off, though, because “if” is _not_ a function.


PointedEars
--
Sometimes, what you learn is wrong. If those wrong ideas are close to the
root of the knowledge tree you build on a particular subject, pruning the
bad branches can sometimes cause the whole tree to collapse.
-- Mike Duffy in cljs, <news:Xns9FB6521286DB8invalidcom(at)94(dot)75(dot)214(dot)39>
Re: Booleans compared to strings [message #181370 is a reply to message #181355] Mon, 13 May 2013 22:21 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
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.
Re: Booleans compared to strings [message #181371 is a reply to message #181368] Mon, 13 May 2013 22:26 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
On 13/05/13 22:22, M. Strobel wrote:
> Am 13.05.2013 22:24, schrieb Doug Cassidy:
>> On Monday, May 13, 2013 6:13:11 AM UTC-7, Jerry Stuckle wrote:
>>> On 5/13/2013 8:29 AM, Doug Cassidy wrote:
>>>> 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.
>> got it, thanks
>>
> My favourite link to comparison in PHP is
> http://www.php.net/manual/en/types.comparisons.php
> where you have also the "if ($x)" results.

Yuk I do not like "0" being a representation of FALSE at all.

> Highly recommended.
>
> /Str.


--
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.
Re: Booleans compared to strings [message #181372 is a reply to message #181369] Mon, 13 May 2013 22:28 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
On 13/05/13 22:46, Thomas 'PointedEars' Lahn wrote:
> M. Strobel wrote:
>
>> Am 13.05.2013 22:24, schrieb Doug Cassidy:
>>> On Monday, May 13, 2013 6:13:11 AM UTC-7, Jerry Stuckle wrote:
>>>> On 5/13/2013 8:29 AM, Doug Cassidy wrote:
>>>> > 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.
>>> got it, thanks
>> My favourite link to comparison in PHP is
>> http://www.php.net/manual/en/types.comparisons.php
>> where you have also the "if ($x)" results.
>>
>> Highly recommended.
> Slighty off, though, because “if” is _not_ a function.
Semantics. It behaves like one, takes two variables and returns a value.

In FORTH its like any other function IIRC, But then everything is a
function , in forth :-)
>
> 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.
Re: Booleans compared to strings [message #181375 is a reply to message #181372] Mon, 13 May 2013 22:41 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
The Natural Philosopher wrote:

> On 13/05/13 22:46, Thomas 'PointedEars' Lahn wrote:
>> M. Strobel wrote:
>>> Am 13.05.2013 22:24, schrieb Doug Cassidy:
>>>> On Monday, May 13, 2013 6:13:11 AM UTC-7, Jerry Stuckle wrote:
>>>> > On 5/13/2013 8:29 AM, Doug Cassidy wrote:
>>>> >> 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.
>>>> got it, thanks
>>> My favourite link to comparison in PHP is
>>> http://www.php.net/manual/en/types.comparisons.php
>>> where you have also the "if ($x)" results.
>>>
>>> Highly recommended.
>> Slighty off, though, because “if” is _not_ a function.
> Semantics. It behaves like one, takes two variables and returns a value.

I am not usually reading your postings because of your notorious address
munging and anonymous posting, but really …

What the *heck* are you talking about? An “if” *statement* does not return
anything (in neither programming language where it is a statement), and it
does not “take two variables”. It is the *one* “parameter” (for lack of a
better word) to the statement that is evaluated to a value, which is then
converted to boolean, which then determines whether or not the adjacent
statement is executed.


PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Re: Booleans compared to strings [message #181376 is a reply to message #181372] Mon, 13 May 2013 22:56 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 5/13/2013 6:28 PM, The Natural Philosopher wrote:
> On 13/05/13 22:46, Thomas 'PointedEars' Lahn wrote:
>> M. Strobel wrote:
>>
>>> Am 13.05.2013 22:24, schrieb Doug Cassidy:
>>>> On Monday, May 13, 2013 6:13:11 AM UTC-7, Jerry Stuckle wrote:
>>>> > On 5/13/2013 8:29 AM, Doug Cassidy wrote:
>>>> >> 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.
>>>> got it, thanks
>>> My favourite link to comparison in PHP is
>>> http://www.php.net/manual/en/types.comparisons.php
>>> where you have also the "if ($x)" results.
>>>
>>> Highly recommended.
>> Slighty off, though, because “if” is _not_ a function.
> Semantics. It behaves like one, takes two variables and returns a value.
>
> In FORTH its like any other function IIRC, But then everything is a
> function , in forth :-)
>>

Who cares about forth? This is a PHP newsgroup.

But then you don't know the difference.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Booleans compared to strings [message #181377 is a reply to message #181371] Mon, 13 May 2013 22:57 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 5/13/2013 6:26 PM, The Natural Philosopher wrote:
> On 13/05/13 22:22, M. Strobel wrote:
>> Am 13.05.2013 22:24, schrieb Doug Cassidy:
>>> On Monday, May 13, 2013 6:13:11 AM UTC-7, Jerry Stuckle wrote:
>>>> On 5/13/2013 8:29 AM, Doug Cassidy wrote:
>>>> > 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.
>>> got it, thanks
>>>
>> My favourite link to comparison in PHP is
>> http://www.php.net/manual/en/types.comparisons.php
>> where you have also the "if ($x)" results.
>
> Yuk I do not like "0" being a representation of FALSE at all.
>

Then create your own language. Or live with what the language defines.



--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Booleans compared to strings [message #181382 is a reply to message #181372] Tue, 14 May 2013 19:36 Go to previous messageGo to next message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
Am 14.05.2013 00:28, schrieb The Natural Philosopher:
> On 13/05/13 22:46, Thomas 'PointedEars' Lahn wrote:
>> M. Strobel wrote:
>>
>>> Am 13.05.2013 22:24, schrieb Doug Cassidy:
>>>> On Monday, May 13, 2013 6:13:11 AM UTC-7, Jerry Stuckle wrote:
>>>> > On 5/13/2013 8:29 AM, Doug Cassidy wrote:
>>>> >> 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.
>>>> got it, thanks
>>> My favourite link to comparison in PHP is
>>> http://www.php.net/manual/en/types.comparisons.php
>>> where you have also the "if ($x)" results.
>>>
>>> Highly recommended.
>> Slighty off, though, because “if” is _not_ a function.
> Semantics. It behaves like one, takes two variables and returns a value.
>
> In FORTH its like any other function IIRC, But then everything is a function , in
> forth :-)

Hmm, in Forth you do 0= or something, then "if" takes a flag off the stack and does a
branch/jump to the else address if the flag is false.

Not easy to see it as a function.

/Str.
Re: Booleans compared to strings [message #181383 is a reply to message #181382] Tue, 14 May 2013 20:17 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
On 14/05/13 20:36, M. Strobel wrote:
> Am 14.05.2013 00:28, schrieb The Natural Philosopher:
>> On 13/05/13 22:46, Thomas 'PointedEars' Lahn wrote:
>>> M. Strobel wrote:
>>>
>>>> Am 13.05.2013 22:24, schrieb Doug Cassidy:
>>>> > On Monday, May 13, 2013 6:13:11 AM UTC-7, Jerry Stuckle wrote:
>>>> >> On 5/13/2013 8:29 AM, Doug Cassidy wrote:
>>>> >>> 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.
>>>> > got it, thanks
>>>> My favourite link to comparison in PHP is
>>>> http://www.php.net/manual/en/types.comparisons.php
>>>> where you have also the "if ($x)" results.
>>>>
>>>> Highly recommended.
>>> Slighty off, though, because “if” is _not_ a function.
>> Semantics. It behaves like one, takes two variables and returns a value.
>>
>> In FORTH its like any other function IIRC, But then everything is a function , in
>> forth :-)
> Hmm, in Forth you do 0= or something, then "if" takes a flag off the stack and does a
> branch/jump to the else address if the flag is false.
>
> Not easy to see it as a function.
try writing the FORTH interpreter...
> /Str.
>


--
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.
Re: Booleans compared to strings [message #181415 is a reply to message #181383] Wed, 15 May 2013 19:34 Go to previous message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
Am 14.05.2013 22:17, schrieb The Natural Philosopher:
> On 14/05/13 20:36, M. Strobel wrote:
>> Am 14.05.2013 00:28, schrieb The Natural Philosopher:
>>> On 13/05/13 22:46, Thomas 'PointedEars' Lahn wrote:
>>>> M. Strobel wrote:
>>>>
>>>> > Am 13.05.2013 22:24, schrieb Doug Cassidy:
>>>> >> On Monday, May 13, 2013 6:13:11 AM UTC-7, Jerry Stuckle wrote:
>>>> >>> On 5/13/2013 8:29 AM, Doug Cassidy wrote:
>>>> >>>> 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.
>>>> >> got it, thanks
>>>> > My favourite link to comparison in PHP is
>>>> > http://www.php.net/manual/en/types.comparisons.php
>>>> > where you have also the "if ($x)" results.
>>>> >
>>>> > Highly recommended.
>>>> Slighty off, though, because “if” is _not_ a function.
>>> Semantics. It behaves like one, takes two variables and returns a value.
>>>
>>> In FORTH its like any other function IIRC, But then everything is a function , in
>>> forth :-)
>> Hmm, in Forth you do 0= or something, then "if" takes a flag off the stack and does a
>> branch/jump to the else address if the flag is false.
>>
>> Not easy to see it as a function.
> try writing the FORTH interpreter...
>> /Str.
>>
>
>
No problem, did it in /370 assembly. You mean because it is an immediate word? but it
is not a function, it does not return a value, only side effects.

/Str.
  Switch to threaded view of this topic Create a new topic Submit Reply
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 Nov 24 06:57:22 GMT 2024

Total time taken to generate the page: 0.02847 seconds