目录

PHP is_callable() 函数

❮ PHP 变量处理参考

示例

检查变量的内容是否可以作为函数调用:

<?php
function test1(){
}

echo "test1 is callable: " . is_callable("test1");
echo "<br>";
echo "test2 is callable: " . is_callable("test2");
?>
亲自试一试 »

定义和用法

is_callable() 函数检查变量的内容是否可以作为函数调用。

如果变量可调用,则该函数返回 true (1),否则返回 false/无任何内容。


语法

is_callable( variable, syntax_only, name );

参数值

Parameter Description
variable Required. Specifies the variable to check
syntax_only Optional. If set to TRUE, the function only verifies if variable is a function or method. It will reject variables that are not strings, or arrays without a valid structure to be used as a callback. Default is false
name Optional. Returns a "callable name" (only for classes)

技术细节

返回值: 如果为真多变的是可调用的,否则为 FALSE
返回类型: 布尔值
PHP 版本: 4.0.6+

❮ PHP 变量处理参考