note 31677 deleted from language.types.boolean by nlopess

From: Date: Thu, 14 Apr 2005 14:55:14 +0000
Subject: note 31677 deleted from language.types.boolean by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-88002@lists.php.net to get a copy of this message
Note Submitter: rachel at NO-UBE dot xtreme dot com ---- 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.

« previous php.notes (#88002) next »