php检测类是否存在,php判断类是否存在函数class_exists用法分析
本文實(shí)例分析了php判斷類是否存在函數(shù)class_exists用法。分享給大家供大家參考。具體如下:
如果我們要判斷一個(gè)類是不是可以用,可以先使用class_exists函數(shù)來判斷一下,下面來看幾個(gè)例子。
bool class_exists ( string $class_name [, bool $autoload = true ] )
此功能是否給定的類被定義檢查。this function checks whether or not the given class has been defined.
返回true,如果class_name是一個(gè)定義的類,否則返回false。
實(shí)例如下:
代碼如下:function __autoload($class)
{
include($class . '.php');
// check to see whether the include declared the class
if (!class_exists($class, false)) {
trigger_error("unable to load class: $class", e_user_warning);
}
}
if (class_exists('myclass')) {
$myclass = new myclass();
}
希望本文所述對(duì)大家的PHP程序設(shè)計(jì)有所幫助。
總結(jié)
以上是生活随笔為你收集整理的php检测类是否存在,php判断类是否存在函数class_exists用法分析的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php星座判断源码,php根据日期判断星
- 下一篇: php 1天,自学PHP之第1天-字符