Reputation:
I know that in php you can use variable functions like:
function some_func(){}
$name = "some_func";
$$name();
But, what I really want to know is if you can check if a function exists without executing it. That is not via:
if($name()){}
Upvotes: 2
Views: 48
Reputation: 196
Use function_exists()
. It will do exactly what you are asking for.
Here's how (from the PHP manual):
bool function_exists( string $name)
It will check the list of defined functions (both built-in and user-defined) for $name
NOTE:
If you wish to check if a member function (method) exists use method_exists
.
Find out more here
Upvotes: 5