note 101142 added to function.gettype
| From: | PPKu-N0-SPAM-schy at mediasoft-berlin dot de | Date: | Mon, 29 Nov 2010 14:57:57 +0000 |
| Subject: | note 101142 added to function.gettype | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-174439@lists.php.net to get a copy of this message | ||
After some testing I found a bug in my function "myGetType":
The check for "is_callable" was done before "is_string", so that something like
<?php echo myGetType("max"); ?> would output: "function reference" instead
of "string"
"is_callable" and "is_string" can't be checked together in this method, so
I've removed the check for is_callable because it's a very rare usage case and if
it's a valid string the check for is_callable never executes because is_string would be reached
first (or vice-versa).
So here is the new function without "is_callable"-Check:
<?php
/**
* Returns the type of the var passed.
*
* @param mixed $var Variable
* @return string Type of variable
*/
function myGetType($var)
{
if (is_array($var)) return "array";
if (is_bool($var)) return "boolean";
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";
}
?>
----
Server IP: 217.160.235.204
Probable Submitter: 93.219.148.178
----
Manual Page -- http://www.php.net/manual/en/function.gettype.php
Edit -- https://master.php.net/note/edit/101142
Del: integrated -- https://master.php.net/note/delete/101142/integrated
Del: useless -- https://master.php.net/note/delete/101142/useless
Del: bad code -- https://master.php.net/note/delete/101142/bad+code
Del: spam -- https://master.php.net/note/delete/101142/spam
Del: non-english -- https://master.php.net/note/delete/101142/non-english
Del: in docs -- https://master.php.net/note/delete/101142/in+docs
Del: other reasons-- https://master.php.net/note/delete/101142
Reject -- https://master.php.net/note/reject/101142
Search -- https://master.php.net/manage/user-notes.php