note 104224 deleted from function.gettype by cmb
| From: | cmb@php.net | Date: | Mon, 02 Nov 2020 21:58:45 +0000 |
| Subject: | note 104224 deleted from function.gettype by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-215778@lists.php.net to get a copy of this message | ||
Note Submitter: langpavel at phpskelet dot org
----
This function returns string representation of type. This is generalization of get_class(). I try to
order is_* tests by density of occurence, but is bad idea to use result of this call in conditions
for performance reasons, usefull and better than gettype for debugging messages.
Note, that last line should not be never executed.
Also has no sense to make input parameter optional.
<?php
function get_type($var)
{
if(is_object($var))
return get_class($var);
if(is_null($var))
return 'null';
if(is_string($var))
return 'string';
if(is_array($var))
return 'array';
if(is_int($var))
return 'integer';
if(is_bool($var))
return 'boolean';
if(is_float($var))
return 'float';
if(is_resource($var))
return 'resource';
//throw new NotImplementedException();
return 'unknown';
}
?>