note 96392 deleted from function.is-string by danbrown
| From: | danbrown@php.net | Date: | Mon, 01 Nov 2010 14:08:56 +0000 |
| Subject: | note 96392 deleted from function.is-string by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173650@lists.php.net to get a copy of this message | ||
Note Submitter: son9ne dot junk at gmail dot com
----
It took me a second to realize what was happening. When checking is_string() on an empty string, it
fails.
ie:
<?php
function fetchType($var) {
# Setup commonly used types (PHP.net warns against using gettype())
switch ($var) {
case is_string($var):
$type='string';
break;
case is_array($var):
$type='array';
break;
case is_null($var):
$type='NULL';
break;
case is_bool($var):
$type='boolean';
break;
case is_int($var):
$type='integer';
break;
case is_float($var):
// $type='float';
$type='double';
break;
case is_object($var):
$type='object';
break;
case is_resource($var):
$type='resource';
break;
default:
$type='unknown type';
break;
}
return $type;
}
echo fetchType('');
?>
will output: array.