note 97854 added to function.is-string
| From: | tavy72 at gmail dot com | Date: | Wed, 12 May 2010 10:54:25 +0000 |
| Subject: | note 97854 added to function.is-string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-169174@lists.php.net to get a copy of this message | ||
Re: When checking is_string() on an empty string, it fails.
You don't use "switch" correctly.
If $var is '' then will evaluate to "false" and is_string($var) will evaluate to
"true" and is_array($var) will evaluate to "false".
Basicaly you have:
switch(''){
case true:
$type='string';
break;
case false:
$type='array';
break;
...
}
In this case you can use a sequance like this:
if( is_string($var) )return 'string';
if( is_array($var) )return 'array';
...
return 'unknown type';
or
if( is_string($var) ) $type='string';
elseif( is_array($var) ) $type='array';
...
else $type='unknown type';
return $type;
Sorry for my bad english.
----
Server IP: 69.147.83.197
Probable Submitter: 89.115.89.2
----
Manual Page -- http://www.php.net/manual/en/function.is-string.php
Edit -- https://master.php.net/note/edit/97854
Del: integrated -- https://master.php.net/note/delete/97854/integrated
Del: useless -- https://master.php.net/note/delete/97854/useless
Del: bad code -- https://master.php.net/note/delete/97854/bad+code
Del: spam -- https://master.php.net/note/delete/97854/spam
Del: non-english -- https://master.php.net/note/delete/97854/non-english
Del: in docs -- https://master.php.net/note/delete/97854/in+docs
Del: other reasons-- https://master.php.net/note/delete/97854
Reject -- https://master.php.net/note/reject/97854
Search -- https://master.php.net/manage/user-notes.php