note 107559 deleted from function.function-exists by danbrown
| From: | danbrown@php.net | Date: | Thu, 10 May 2012 20:45:22 +0000 |
| Subject: | note 107559 deleted from function.function-exists by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-187833@lists.php.net to get a copy of this message | ||
Note Submitter: scragar at gmail dot com
----
"Michael dot Bond at mail dot wvu dot edu" posted a pretty good function, but he forgot
something, the language constructs like exit and eval are case insensitive.
EXIT, ExIt and exiT all work exactly the same.
<?php
function functionExists($param1,$param2=null) {
$langConstructs = array("die",
"echo", "empty", "exit", "eval",
"include", "include_once", "isset",
"list",
"print",
"require", "require_once",
"unset"
);
// 2 params provided, assume class
if (!is_null($param2)) {
return(method_exists($param1,$param2));
}
// Ignore everything that isn't a string, from this point on
if (!is_string($param1)) {
return(FALSE);
}
// check if function exists
if (function_exists($param1) === TRUE) {
return(TRUE);
}
// Check to see if it is an object being passed as a string.
// if so, assume object
$items = explode("::",$param1);
if (count($items) == 2) {
return(method_exists($items[0],$items[1]));
}
$items = explode("->",$param1);
if (count($items) == 2) {
return(method_exists($items[0],$items[1]));
}
// check to see if it is a language construct
return (in_array(strToLower($param1),$langConstructs));
}
?>
Should avoid this little problem. Other than that it's a very cool little function.