note 100299 added to function.gettype

From: Date: Wed, 06 Oct 2010 16:46:45 +0000
Subject: note 100299 added to function.gettype
Groups: php.notes 
Request: Send a blank email to php-notes+get-173034@lists.php.net to get a copy of this message
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); ---- Server IP: 192.41.42.26 Probable Submitter: 204.137.29.243 ---- Manual Page -- http://www.php.net/manual/en/function.gettype.php Edit -- https://master.php.net/note/edit/100299 Del: integrated -- https://master.php.net/note/delete/100299/integrated Del: useless -- https://master.php.net/note/delete/100299/useless Del: bad code -- https://master.php.net/note/delete/100299/bad+code Del: spam -- https://master.php.net/note/delete/100299/spam Del: non-english -- https://master.php.net/note/delete/100299/non-english Del: in docs -- https://master.php.net/note/delete/100299/in+docs Del: other reasons-- https://master.php.net/note/delete/100299 Reject -- https://master.php.net/note/reject/100299 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#173034) next »