note 101142 deleted from function.gettype by cmb

From: Date: Mon, 02 Nov 2020 21:59:26 +0000
Subject: note 101142 deleted from function.gettype by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-215780@lists.php.net to get a copy of this message
Note Submitter: PPKu-N0-SPAM-schy at mediasoft-berlin dot de ---- 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"; } ?>

« previous php.notes (#215780) next »