首頁  >  文章  >  php教程  >  php判断类是否存在函数 class_exists

php判断类是否存在函数 class_exists

WBOY
WBOY原創
2016-06-13 11:17:381332瀏覽

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