ホームページ  >  記事  >  php教程  >  php判断类是否存在函数 class_exists

php判断类是否存在函数 class_exists

WBOY
WBOYオリジナル
2016-06-13 11:17:381331ブラウズ

php判断类是否存在函数 class_exists//bool class_exists ( string $class_name [, bool $autoload = true ] )//此功能是否给定的类被定义检查。This function checks whether or not the given class has been defined.  

php教程判断类是否存在函数 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。
//实例

if (class_exists('myclass')) {
    $myclass = new myclass();
}

 

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();
}


声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。