note 47409 added to language.types.boolean
| From: | dot) | Date: | Mon, 15 Nov 2004 20:24:18 +0000 |
| Subject: | note 47409 added to language.types.boolean | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-80556@lists.php.net to get a copy of this message | ||
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....
----
Manual Page -- http://www.php.net/manual/en/language.types.boolean.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47409
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47409&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47409&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47409&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47409&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47409&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47409&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47409&report=yes
Search -- http://master.php.net/manage/user-notes.php