function_exists()
判断函数是否已定义,常用于检测扩展是否安装。
function_exists(string $function): bool
参数
| 参数 | 类型 | 说明 |
|---|---|---|
$function | string | 函数名 |
返回值
bool — 存在返回 true。
示例
var_dump(function_exists('curl_init'));
if (!function_exists('mb_strlen')) {
exit('缺少 mbstring 扩展');
}输出
bool(true)
注意
- 用来做「有就用,没有就降级」的兼容处理。
- 类方法用 method_exists 判断。