note 104224 added to function.gettype
| From: | langpavelatphpskeletdotorg at osu1 dot php dot net | Date: | Thu, 02 Jun 2011 03:20:45 +0000 |
| Subject: | note 104224 added to function.gettype | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-180180@lists.php.net to get a copy of this message | ||
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';
}
----
Server IP: 85.214.154.209
Probable Submitter: 62.240.163.46
----
Manual Page -- http://www.php.net/manual/en/function.gettype.php
Edit -- https://master.php.net/note/edit/104224
Del: integrated -- https://master.php.net/note/delete/104224/integrated
Del: useless -- https://master.php.net/note/delete/104224/useless
Del: bad code -- https://master.php.net/note/delete/104224/bad+code
Del: spam -- https://master.php.net/note/delete/104224/spam
Del: non-english -- https://master.php.net/note/delete/104224/non-english
Del: in docs -- https://master.php.net/note/delete/104224/in+docs
Del: other reasons-- https://master.php.net/note/delete/104224
Reject -- https://master.php.net/note/reject/104224
Search -- https://master.php.net/manage/user-notes.php