php判断类是否存在函数class_exists用法分析

原创 2017-02-13 10:26:39 320
摘要:本文实例分析了php判断类是否存在函数class_exists用法。分享给大家供大家参考。具体如下:如果我们要判断一个类是不是可以用,可以先使用class_exists函数来判断一下,下面来看几个例子。bool class_exists ( string $class_name [, bool $autoload = true ] )此功能是否给定的类被定义检查。this function che

本文实例分析了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。

实例如下:

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判断类是否存在函数class_exists用法分析请关注PHP中文网(www.php.cn)其他文章!

发布手记

热门词条