Verify that the contents of a variable can be called as a function in PHP
Description
The following code shows how to verify that the contents of a variable can be called as a function.
Example
<?php//from w ww .j a v a 2 s .c om
//How to check a variable to see if it can be called as a function.
// Simple variable containing a function
function someFunction(){}
$functionVariable = 'someFunction';
var_dump(is_callable($functionVariable, false, $callable_name)); // bool(true)
echo $callable_name, "\n"; // someFunction
// Array containing a method
class someClass {
function someMethod(){}
}
$anObject = new someClass();
$methodVariable = array($anObject, 'someMethod');
var_dump(is_callable($methodVariable, true, $callable_name)); // bool(true)
echo $callable_name, "\n"; // someClass::someMethod
?>
The code above generates the following result.