note 98996 deleted from function.is-string by danbrown
| From: | danbrown@php.net | Date: | Wed, 21 Jul 2010 13:45:08 +0000 |
| Subject: | note 98996 deleted from function.is-string by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-171012@lists.php.net to get a copy of this message | ||
Note Submitter: Compvir
----
Dear son9ne dot junk at gmail dot com.
The thing is that it is your function fetchType is working wrong.
It also will say that the following variables are strings: false, 0, null - though they are bool,
integer and null respectfully.
The mistake is that you compares $var with the result of is_<type>($var). If $var is some type
then is_<type>($var) will return true and thereafter you should make the following code to
receive correct answer:
<?php
function fetchType($var) {
# Setup commonly used types (PHP.net warns against using gettype())
switch (true) {
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('');
?>