参考地址:http://www.ggat.cn/newsInfo.html/10
PHP中提供了几个函数分别用来检测常量、变量、函数、类是否存在:
常量检测使用defined,定义常量则是define。注意待检测的常量需要使用引号(单双均可),如:
复制
if (defined("CONST_NAME")) { ... }
变量检测则是使用isset,注意变量未声明或声明时赋值为NULL,isset均返回FALSE,如:
复制
if (isset($var_name)) { ...}
函数检测用function_exists,注意待检测的函数名也需要使用引号,如:
复制
if (function_exists('fun_name')) { fun_name();}
检测类是否存在使用 class_exists,同样类名需要使用引号,如:
复制
if (class_exists('class_name')) { $o = new class_name();}