note 36261 added to language.types.boolean

From: Date: Thu, 02 Oct 2003 16:46:11 +0000
Subject: note 36261 added to language.types.boolean
Groups: php.notes 
Request: Send a blank email to php-notes+get-57622@lists.php.net to get a copy of this message
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 ?> ---- Manual Page -- http://www.php.net/manual/en/language.types.boolean.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+36261 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+36261&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+36261&report=yes

« previous php.notes (#57622) next »