note 97854 deleted from function.is-string by danbrown
| From: | danbrown@php.net | Date: | Wed, 12 May 2010 14:03:00 +0000 |
| Subject: | note 97854 deleted from function.is-string by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-169181@lists.php.net to get a copy of this message | ||
Note Submitter: tavy72 at gmail dot com
----
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.