时时商务社区

标题: php判断类是否存在函数class_exists用法分析 [打印本页]

作者: 阿情    时间: 2018-2-14 05:52

            本文实例分析了php判断类是否存在函数class_exists用法。分享给大家供大家参考。具体如下:
如果我们要判断一个类是不是可以用,可以先使用class_exists函数来判断一下,下面来看几个例子。
bool class_exists ( string $class_name [, bool $autoload = true ] )
此功能是否给定的类被定义检查。this function checks whether or not the given class has been defined.
返回true,如果class_name是一个定义的类,否则返回false。
实例如下:
[U]复制代码[/U] 代码如下: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();
}
希望本文所述对大家的PHP程序设计有所帮助。
            
            
您可能感兴趣的文章:
  • PHP 判断常量,变量和函数是否存在
  • php file_exists 检查文件或目录是否存在的函数
  • php !function_exists("T7FC56270E7A70FA81A5935B72EACBE29"))代码解密
  • PHP数组对比函数,存在交集则返回真,否则返回假
  • PHP strstr 函数判断字符串是否否存在的实例代码
  • php使用function_exists判断函数可用的方法
  • PHP使用get_headers函数判断远程文件是否存在的方法
  • php通过function_exists检测函数是否存在的方法
            




    欢迎光临 时时商务社区 (http://bbs.4435.cn/) Powered by Discuz! X3.2