note 36261 rejected from language.types.boolean by pollita

From: Date: Thu, 02 Oct 2003 17:14:33 +0000
Subject: note 36261 rejected from language.types.boolean by pollita
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-57623@lists.php.net to get a copy of this message
Note Submitter: rbotzer@yahoo.com ---- I ran into some insane behavior, and I would hope that this will get fixed at some point. It seems that the result string "false" (I ran into this while dealing with return values from a SOAP call) turns into TRUE when type-cast into a boolean. Seriously, type casting can be extended _a_little_ to cover this nonsensical case. Just so you're aware that this is what happens. Here's some example code: <?php // start example: $x = "false"; if ($x === "false") { print ("the string value of x is evaluating as \"false\" \n"); var_dump ($x); print ("\n"); } $y = (boolean) $x; print ("\$x was type-cast into boolean \$y\n\n"); if ($y) { print ("the boolean value of x is evaluating as true\n"); var_dump ($y); } // end example ?>

« previous php.notes (#57623) next »