3v4l.org

run code in 300+ PHP versions simultaneously
<?php // 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

preferences:
33.64 ms | 402 KiB | 5 Q