note 100297 added to function.is-string
| From: | derek dot p dot moore at gmail dot com | Date: | Wed, 06 Oct 2010 16:06:10 +0000 |
| Subject: | note 100297 added to function.is-string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-173025@lists.php.net to get a copy of this message | ||
son9ne's note below isn't entirely accurate, consider the following code:
$test = '';
function func($var) { return $var; }
function func2($var) {
switch ($var) {
case is_string($var): return $var;
case is_array($var): return $var;
}
}
function func3($var) {
switch ($var) {
case is_string($var): print "string!"; break;
case is_array($var): print "array!"; break;
}
}
if (is_array($test)): print "array!"; elseif (is_string($test)): print
"string!"; endif;
if (is_array(func($test))): print "array!"; elseif (is_string(func($test))): print
"string!"; endif;
if (is_array(func2($test))): print "array!"; elseif (is_string(func2($test))): print
"string!"; endif;
func3($test);
It will output: string! string! string! array!
I would expect the output: string! string! string! string!
I think this is a bug in PHP's switch statement.
----
Server IP: 69.147.83.197
Probable Submitter: 204.137.29.243
----
Manual Page -- http://www.php.net/manual/en/function.is-string.php
Edit -- https://master.php.net/note/edit/100297
Del: integrated -- https://master.php.net/note/delete/100297/integrated
Del: useless -- https://master.php.net/note/delete/100297/useless
Del: bad code -- https://master.php.net/note/delete/100297/bad+code
Del: spam -- https://master.php.net/note/delete/100297/spam
Del: non-english -- https://master.php.net/note/delete/100297/non-english
Del: in docs -- https://master.php.net/note/delete/100297/in+docs
Del: other reasons-- https://master.php.net/note/delete/100297
Reject -- https://master.php.net/note/reject/100297
Search -- https://master.php.net/manage/user-notes.php