Created
October 3, 2010 23:30
-
-
Save AlyxRen/609049 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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