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 家长回复节日祝福语简短
18 给外婆敬酒祝福语简短