note 69243 added to language.types.boolean
| From: | shadow4 dot at-jouwmoeder at osu1 dot php dot net | Date: | Mon, 28 Aug 2006 13:44:47 +0000 |
| Subject: | note 69243 added to language.types.boolean | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-116433@lists.php.net to get a copy of this message | ||
if ( $var )
will always result the exact same as
if ( TRUE === (bool)$var )
That's interesting, since "a" turns to TRUE when (bool) is used and 0 turns to FALSE,
though "a" == 0.
The following example is self explaining:
<?php
$var = "a";
echo "\$var = $var<br/><br/>";
if ( $var ) echo 'if ( $var ) >> TRUE';
else echo 'if ( $var ) >> FALSE';
echo "<br/><br/>";
if ( TRUE === (bool)$var ) echo 'if ( TRUE === (bool)$var ) >> TRUE';
else echo 'if ( TRUE === (bool)$var ) >> FALSE';
echo "<br/><br/>though<br/><br/>";
if ( "a" == 0 ) echo "'a' == 0 >> TRUE";
else echo "'a' == 0 >> FALSE";
?>
I did not include if ( 0 ) because it's quite obvious that 0 will turn to FALSE, always.
For whom doesn't understand:
"a" is TRUE
0 is FALSE
( "a" == 0 ) is TRUE
That's weird, isnt it? :)
----
Server IP: 194.109.193.119
Probable Submitter: 217.195.249.69
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/language.types.boolean.php
Edit -- https://master.php.net/note/edit/69243
Del: integrated -- https://master.php.net/note/delete/69243/integrated
Del: useless -- https://master.php.net/note/delete/69243/useless
Del: bad code -- https://master.php.net/note/delete/69243/bad+code
Del: spam -- https://master.php.net/note/delete/69243/spam
Del: non-english -- https://master.php.net/note/delete/69243/non-english
Del: in docs -- https://master.php.net/note/delete/69243/in+docs
Del: other reasons-- https://master.php.net/note/delete/69243
Reject -- https://master.php.net/note/reject/69243
Search -- https://master.php.net/manage/user-notes.php