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