is_callable()函数用于检查指定的函数是否可调用。
用法: bool is_callable ( mixed $var [, bool $syntax_only = false [, string &$callable_name ]] )
参数:
返回值: 如果函数可调用,则返回true,否则返回false。
示例:
function myFunction() {
echo "Hello, World!";
}
if (is_callable('myFunction')) {
echo "myFunction is callable!";
} else {
echo "myFunction is not callable!";
}
class MyClass {
public function myMethod() {
echo "Hello, World!";
}
}
$obj = new MyClass();
if (is_callable([$obj, 'myMethod'])) {
echo "myMethod is callable!";
} else {
echo "myMethod is not callable!";
}
class MyClass {
public static function myStaticMethod() {
echo "Hello, World!";
}
}
if (is_callable(['MyClass', 'myStaticMethod'])) {
echo "myStaticMethod is callable!";
} else {
echo "myStaticMethod is not callable!";
}