1.function_exists — 如果给定的函数已经被定义就返回TRUE
参数
-
函数名,必须为一个字符串。
function_name
返回值
如果 function_name
存在且的确是一个函数就返回 TRUE
,反之则返回 FALSE
。
Note:
对于语法结构的判断,例如 include_once 和echo 将会返回
FALSE
。范例
Example #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";
}
?>
参数
-
对象示例或者类名。
-
方法名。
object
method_name
返回值
如果 method_name
所指的方法在 object
所指的对象类中已定义,则返回 TRUE
,否则返回 FALSE
。
Example #1 method_exists() 例子
<?php
$directory = new Directory('.');
var_dump(method_exists($directory,'read'));
?>
以上例程会输出:
bool(true)
Example #2 Static method_exists() 例子
<?php
var_dump(method_exists('Directory','read'));
?>
以上例程会输出:
bool(true)