downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  

<call_user_methodget_class_methods>
Last updated: Thu, 26 Jun 2008

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 checks whether or not the given class has been defined.

Parameters

class_name

The class name. The name is matched in a case-insensitive manner.

autoload

Whether or not to call __autoload by default. Defaults to TRUE.

Return Values

Returns TRUE if class_name is a defined class, FALSE otherwise.

ChangeLog

Version Description
5.0.2 No longer returns TRUE for defined interfaces. Use interface_exists().
5.0.0 The autoload parameter was added.

Examples

Example #1 class_exists() example

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

?>

Example #2 autoload parameter example

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

?>



add a noteadd a note User Contributed Notes
Checks if the class has been defined
There are no user contributed notes for this page.




<call_user_methodget_class_methods>
Last updated: Thu, 26 Jun 2008
show source | credits | sitemap | contact | advertising | mirror sites
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: http://phpbuilder.com/
Last updated: Tue Nov 1 20:20:59 2005 EST
Columns / Articles | Tips / Quickies | News | News Linking and RSS Feeds | Shared Code Library
Mail Archives | Support / Discussion Forums | Get Started! Links | Contribute! | Docs