note 90037 deleted from language.types.boolean by cmb
| From: | cmb@php.net | Date: | Fri, 15 May 2015 18:53:15 +0000 |
| Subject: | note 90037 deleted from language.types.boolean by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-202536@lists.php.net to get a copy of this message | ||
Note Submitter: russell dot harper at springboardnetworks dot com
----
PHP is very fussy converting strings to booleans. The only ones it recognizes are '0' or
'', everything else evaluates to TRUE, even 'false' and '0.0' are
evaluated as true! I suppose this can't be fixed without breaking a lot of existing code.
Example:
<?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.0'."\t".((bool)'0.0'? 1: 0)."\n";
print ''."\t".((bool)''? 1: 0)."\n";
?>
Output:
yes 1
true 1
no 1
false 1
1 1
0 0
0.0 1
0