note 92257 added to language.types.boolean
| From: | snoatcomxnetdotdk at osu1 dot php dot net | Date: | Thu, 16 Jul 2009 09:28:27 +0000 |
| Subject: | note 92257 added to language.types.boolean | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-158362@lists.php.net to get a copy of this message | ||
@ 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
----
Server IP: 195.184.96.15
Probable Submitter: 87.72.212.230
----
Manual Page -- http://www.php.net/manual/en/language.types.boolean.php
Edit -- https://master.php.net/note/edit/92257
Del: integrated -- https://master.php.net/note/delete/92257/integrated
Del: useless -- https://master.php.net/note/delete/92257/useless
Del: bad code -- https://master.php.net/note/delete/92257/bad+code
Del: spam -- https://master.php.net/note/delete/92257/spam
Del: non-english -- https://master.php.net/note/delete/92257/non-english
Del: in docs -- https://master.php.net/note/delete/92257/in+docs
Del: other reasons-- https://master.php.net/note/delete/92257
Reject -- https://master.php.net/note/reject/92257
Search -- https://master.php.net/manage/user-notes.php