php判断类是否存在函数class_exists用法分析
本文实例分析了php判断类是否存在函数class_exists用法。分享给大家供大家参考。具体如下:
如果我们要判断一个类是不是可以用,可以先使用class_exists函数来判断一下,下面来看几个例子。
boolclass_exists(string$class_name[,bool$autoload=true])
此功能是否给定的类被定义检查。thisfunctioncheckswhetherornotthegivenclasshasbeendefined.
返回true,如果class_name是一个定义的类,否则返回false。
实例如下:
function__autoload($class)
{
include($class.'.php');
//checktoseewhethertheincludedeclaredtheclass
if(!class_exists($class,false)){
trigger_error("unabletoloadclass:$class",e_user_warning);
}
}
if(class_exists('myclass')){
$myclass=newmyclass();
}
希望本文所述对大家的PHP程序设计有所帮助。
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短