w3-tools.com - Free Webmaster Tools and Resources
 
w3-tools.com - Free Webmaster Tools and Resources
 Free Webmaster Tools and Resources

 



PHP Manual

This manual is provided as a courtesy. It is not an official source. Please check php.net for updated information.

PHP Manual

PHP Manual

class_exists

(PHP 4, PHP 5)

class_exists -- Checks if the class has been defined

Description

bool class_exists ( string class_name [, bool autoload] )

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

Example 1. class_exists() example

<?php
// Check the class exists before trying to use it
if (class_exists('MyClass')) {
    
$myclass = new MyClass();
}

?>

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.

Example 2. autoload parameter example

<?php
function __autoload($class)
{
    include(
$class . '.php');

    
// Check to see if 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();
}

?>

Note: The autoload parameter was added in PHP 5

See also interface_exists(), and get_declared_classes().

Newsletter

Join to our newsletter and receive news and updates about our site.
Your name: 
E-mail address: 
Action: 
 

Hosted by

Search

Google
Web w3-tools.com

Links

  What is my IP? Find your IP address!     Valid XHTML 1.0 Transitional  
Copyright © 2006. by w3-tools.com. All rights reserved