note 98261 deleted from function.gettype by thiago
| From: | thiago@php.net | Date: | Mon, 29 Nov 2010 13:25:34 +0000 |
| Subject: | note 98261 deleted from function.gettype by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-174438@lists.php.net to get a copy of this message | ||
Note Submitter: son9ne at gmail dot com
----
This is my work around for the gettype warning. Hope some find it useful.
<?php
/**
* Returns the type of the passed var
* - PHP warns against using gettype(), this is my workaround
*
* @param mixed $var
* @return string
*/
public function fetchType($var) {
switch ($var) {
case is_null($var):
$type='NULL';
break;
case is_bool($var):
$type='boolean';
break;
case is_float($var):
$type='double';
// $type='float';
break;
case is_int($var):
$type='integer';
break;
case is_string($var):
$type='string';
break;
case is_array($var):
$type='array';
break;
case is_object($var):
$type='object';
break;
case is_resource($var):
$type='resource';
break;
default:
$type='unknown type';
break;
}
return $type;
}
?>