Skip to content

Instantly share code, notes, and snippets.

@AlyxRen
Created August 11, 2010 19:38
Show Gist options
  • Save AlyxRen/519583 to your computer and use it in GitHub Desktop.
Save AlyxRen/519583 to your computer and use it in GitHub Desktop.
<?php
/*!
* class Is
* Provides Static methods to determine the type on an inputted element.
* Also exposes functions nessicary to test if [[Type]].
*
* Usage::
* if ( Is::_Array($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