English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
is_callable() The function is used to check if a function is callable in the current environment.
is_callable() The function verifies whether the content of the variable can be called as a function. This can check variables containing valid function names, or an array that contains correctly encoded objects and function names.
PHP version requirement: PHP 4 >= 4.0.6, PHP 5, PHP 7
bool is_callable ( callable $name [, bool $syntax_only = false [, string &$callable_name ]] )
Parameter description:
If the name is callable, it returns TRUE, otherwise it returns FALSE...
<?php // Check if the variable is a callable function function someFunction() { } $functionVariable = 'someFunction'; var_dump(is_callable($functionVariable, false, $callable_name)); // bool(true) echo $callable_name, "\n"; // someFunction // // The array contains 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 output result is:
bool(true) someFunction bool(true) someClass::someMethod