note 100299 deleted from function.gettype by danbrown
| From: | danbrown@php.net | Date: | Wed, 06 Oct 2010 16:52:42 +0000 |
| Subject: | note 100299 deleted from function.gettype by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173037@lists.php.net to get a copy of this message | ||
Note Submitter: derek dot p dot moore at gmail dot com
----
The reason for the difference in son9ne's examples is this:
Through PHP's loose typing an empty string is both int 0 & boolean false. Switch on string
is rendering the empty string to false, so the switch matches the false of is_array() not the true
of is_string() !!!
Also, through loose typing a string without leading non-zero numbers is both int 0 & boolean
true (oddly enough, it is both true & false at the same time). But in the case of non-empty
strings with no leading digits, switch works as expected rendering the numberless string to boolean
true not int 0 false, so the switch matches the true of is_string() not the false of is_array() !!!
$test = " ";
var_dump((int) $test);
var_dump((bool) $test);
var_dump((bool) (int) $test);
var_dump((bool) (bool) $test);