rachel at NO-UBE dot xtreme dot com
30-Apr-2003 12:49
If you aren't sure whether your variable is actually a boolean or not, be
very careful with it. For whatever reason, a true boolean is stored as the
number 1, and a false boolean is stored as nothing, null, empty string, or
whatnot. Thus,
$myBool = true ; print( $myBool ) ;
is
indistinguishable from
print( "" )
;
likewise,
&myBool = false ; print( $myBool )
;
is indistinguishable from
print( 1 ) ;
In addition
to the above warnings about boolean evaluation, note that testing for
equality is particularly unintuitive. In particular, "false" the
string will equate to true. For example,
$myTrueBool = true
;
if( $myTrueBool == "true" ) print("it's true!")
;
if( $myTrueBool == "false" ) print("it's false!")
;
if( $myTrueBool == "mushroom" ) print("it's a
mushroom!") ;
if( $myTrueBool == 4 ) print("it's the number
4!") ;
will print out
it's true!
it's false!
it's
a mushroom!
it's the number 4!
But if $myTrueBool were false,
instead, you'd get nothing at all. Caveat Usor.