class_exists() returns true if the specified class is defined.
bool class_exists ( string $class_name [, bool $autoload = true ] )
Returns TRUE if class_name is a defined class, FALSE otherwise.
Check that the class exists before trying to use it
<?php
if (class_exists('MyClass')) {
$myclass = new MyClass();
}
?>
autoload parameter example
<?php//ww w.j a v a 2s .c om
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();
}
?>