note 98312 modified in function.gettype by thiago
| From: | thiago@php.net | Date: | Mon, 29 Nov 2010 13:25:09 +0000 |
| Subject: | note 98312 modified in function.gettype by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-174436@lists.php.net to get a copy of this message | ||
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
*/
function myGetType($var)
{
if (is_array($var)) return "array";
if (is_bool($var)) return "boolean";
if (is_callable($var)) return "function reference";
if (is_float($var)) return "float";
if (is_int($var)) return "integer";
if (is_null($var)) return "NULL";
if (is_numeric($var)) return "numeric";
if (is_object($var)) return "object";
if (is_resource($var)) return "resource";
if (is_string($var)) return "string";
return "unknown type";
}
?>
[EDITOR thiago NOTE: Code has been updated by PPKu-N0-SPAM-schy at mediasoft-berlin dot de]
--was--
The code below needs to be updated to work properly. I found that this way seems to work much
better.
<?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) {
if (is_bool($var)) $type='boolean';
else if (is_int($var)) $type='integer';
else if (is_float($var)) $type='float';
else if (is_string($var)) $type='string';
else if (is_array($var)) $type='array';
else if (is_object($var)) $type='object';
else if (is_resource($var)) $type='resource';
else if (is_null($var)) $type='NULL';
else $type='unknown type';
return $type;
}
?>
http://php.net/manual/en/function.gettype.php