Locale Page...  Global  |  Germany  |  UK  |  USA
Your privat CyberGadget - The finest Resources for Web-Designer, Web-Master and Web-Developer!
Quick Search
Advertisement
Partner & Friends
Developersdex
Tutorial Guide
Send News    Add URL / Entry    Tag it:digg it!Stumble It!YahooMyWeb!del.icio.us!Simpify!reddit!Netvouz!Ma.gnolia!FurlIt!Blogmarks!BlinkList!
PHP Manual by the PHP Documentation Group php.net

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().


© 2001 - 2009 CYGAD.NET | All rights reserved. | Terms of Service | About | Time data: GMT +1! | Portal Release X2.6.1 Beta | RunTime: 0.9853
Optimized for Internet Explorer Internet Explorer 6.0+, Firefox Firefox 1.5+!