note 47409 deleted from language.types.boolean by bobby

From: Date: Thu, 28 Sep 2006 15:15:13 +0000
Subject: note 47409 deleted from language.types.boolean by bobby
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-117782@lists.php.net to get a copy of this message
Note Submitter: x123 (at) bestof (dash) inter (dot) net ---- another correction to the preceding "correction": "as the documention states" is right, "any non-empty string is true" is wrong : (bool) "0" === false ! (but "00" and "0.0" etc. are true!) So watch out, you can NOT test for non-empty strings using e.g. <?php if (is_string($s)) if ($s) echo " '$s' is a non-empty string"; else echo " '$s' is an empty string"; // wrong for $s='0' ! else echo " $s is not a string "; ?> indeed, for $s='0' this would print: " '0' is an empty string" which is wrong, of course. This is particularly "dangerous" in connection with MySQL which prints FALSE by default as 0, which comes back from a FORM POST as string '0', while PHP prints FALSE as empty string (!); a similar problem is to preserve a NULL value through a FORM post....

« previous php.notes (#117782) next »