There are all kinds of potential problems with what you're asking. However if I understand you right, you simply want to know if somename
can be called like somename('someinput')
.
If that's true, then it appears you need to use a combination of function_exists
and a manual lookup of language constructs from the List of Keywords.
Something like this perhaps:
function canICall($function) {
$callableConstructs = array("empty","unset","eval","array","exit","isset","list");
return function_exists($function) || in_array($function, $callableConstructs);
}
That $callableConstructs
array is not complete, look at the List of Keywords page to build it out.
Yes it is hackish, but without a built-in way to do this in PHP I don't see another option.
Note that just because you can call something like a function, does not make it a function, nor does it mean that it behaves like a function in other ways.
You cannot call it dynamically:
$var = "empty";
$var('someinput'); // Does NOT work
Nor does this work:
call_user_func('empty', $foo);
You could use it in an eval
call, but I hope you understand the huge list of reasons why that can be dangerous.