note 69243 deleted from language.types.boolean by colder
| From: | colder@php.net | Date: | Tue, 17 Oct 2006 18:51:31 +0000 |
| Subject: | note 69243 deleted from language.types.boolean by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-118661@lists.php.net to get a copy of this message | ||
Note Submitter: shadow4.at-jouwmoeder,dot-nl
----
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? :)