Skip to content

Instantly share code, notes, and snippets.

@AlyxRen
Created October 3, 2010 23:30
Show Gist options
  • Save AlyxRen/609049 to your computer and use it in GitHub Desktop.
Save AlyxRen/609049 to your computer and use it in GitHub Desktop.
<?php
/*!
* class Is
* (c) Stephen Middleton 2010
* Liscensed under the MIT Liscense
* <http://www.opensource.org/licenses/mit-license.html>
* Provides Static methods to determine the type on an inputted element.
* Also exposes functions nessicary to test if [[Type]].
*
* Usage::
* if ( Is::_Array($arr) ){...}
* if ( Is::_Test($arr) ){...}
* $typeof = Is::_Test($variable);
*/
class Is {
public static $calls = array(
"array", "string",
"integer", "float",
"object", "boolean",
"null"
);
public function _Test($inp){
foreach (self::$calls as $val){
$call = "_" . ucfirst($val);
if (self::$call($inp)){
return $val;
}
}
}
public function _Array($inp){
if (is_object($inp)){
return false;
}
return (bool)((array)$inp === $inp);
}
public function _String($inp){
if (is_object($inp)){
return false;
}
return (bool)((string)$inp === $inp);
}
public function _Integer($inp){
if (is_object($inp)){
return false;
}
return (bool)((int)$inp === $inp);
}
public function _Float($inp){
if (is_object($inp)){
return false;
}
return (bool)((float)$inp === $inp);
}
public function _Object($inp){
return is_object($inp);
}
public function _Boolean($inp){
if (is_object($inp)){
return false;
}
return (bool)((bool)$inp === $inp);
}
public function _Null($inp){
if (is_object($inp)){
return false;
}
return (bool)((unset)$inp === $inp);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment