function_exists

(PHP 4, PHP 5, PHP 7, PHP 8)

function_exists如果给定的函数已经被定义就返回 true

说明

function_exists(string $function): bool

在已经定义的函数列表(包括系统自带的函数和用户自定义的函数)中查找 function

参数

function

函数名,必须为一个字符串。

返回值

如果 function 存在且的确是一个函数就返回 true,反之则返回 false

注意:

对于语法结构的判断,例如 include_onceecho 将会返回 false

范例

示例 #1 function_exists() 的例子

<?php
if (function_exists('imap_open')) {
echo
"IMAP functions are available.<br />\n";
} else {
echo
"IMAP functions are not available.<br />\n";
}
?>

注释

注意:

即使函数本身由于配置或者编译选项而无法使用,该函数名也可能存在(image 就是一个现成的例子)。

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top