note 92257 deleted from language.types.boolean by thiago
| From: | thiago@php.net | Date: | Thu, 16 Jul 2009 12:20:46 +0000 |
| Subject: | note 92257 deleted from language.types.boolean by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-158366@lists.php.net to get a copy of this message | ||
Note Submitter: sno at comxnet dot dk
----
@ russell dot harper at springboardnetworks dot com
You are not testing whether false or 0.0 evalutes to FALSE but whether the strings containing
'false' or '0.0' evalutes to FALSE.
Numbers are never quoted, neither are true and false.
The only non-empty string that evaluates to FALSE is '0'.
So your test should have been:
<?php
print 'yes'."\t".((bool)'yes'? 1: 0)."\n";
print 'true'."\t".((bool)true? 1: 0)."\n";
print 'no'."\t".((bool)'no'? 1: 0)."\n";
print 'false'."\t".((bool)false? 1: 0)."\n";
print '1'."\t".((bool)1? 1: 0)."\n";
print '0'."\t".((bool)'0'? 1: 0)."\n";
print '0'."\t".((bool)0? 1: 0)."\n";
print '0.0'."\t".((bool)0.0? 1: 0)."\n";
print ''."\t".((bool)''? 1: 0)."\n";
?>
which prints
yes 1
true 1
no 1
false 0
1 1
0 0
0 0
0.0 0
0