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 婆婆66岁祝福语简短
13 今天孩子高考祝福语简短
14 送彩票生日祝福语简短
15 分别祝福语简短情话英文
16 画室揭牌仪式祝福语简短
17 女友妈妈生日祝福语简短
18 离别赠言离职祝福语简短