PHP 手冊
上一頁 |  | 下一頁

# class_exists

(PHP 4 , PHP 5)

class_exists -- Checks if the class has been defined

## Description

bool class_exists ( string class_name [, bool autoload])

> 備注: The autoload parameter was added in PHP 5

This function returns `TRUE` if the class given by class_name has been defined, `FALSE` otherwise.

class_exists() will attempt to call __autoload by default, if you don't want class_exists() to call __autoload(), you can set the parameter autoload to `FALSE`.

示範 1.autoload parameter example

`<?php function __autoload($class) { include($class . '.php'); /* Check to see it the include defined the class */ if ( !class_exists($class, false) ) { trigger_error("Unable to load class $class", E_USER_ERROR); } } if( class_exists('MyClass') ) { $myclass = new MyClass(); } ?>`

See also get_declared_classes().

上一頁 | 最開頭 | 下一頁
call_user_method | 上一層 | get_class_methods