note 96392 modified in function.is-string by danbrown
| From: | danbrown@php.net | Date: | Wed, 24 Feb 2010 22:13:04 +0000 |
| Subject: | note 96392 modified in function.is-string by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-166341@lists.php.net to get a copy of this message | ||
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.
--was--
It took me a second to realize what was happening. When checking is_string() on an empty string, it
fails.
ie:
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.
http://php.net/manual/en/function.is-string.php