English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP tutorial

Advanced PHP tutorial

PHP & MySQL

PHP reference manual

PHP class_exists() function usage and example

PHP Class/Object function reference manual

The class_exists() function checks if the class is defined

Syntax

class_exists ( $class_name [,$autoload] );

Definition and usage

This function checks if the given class is defined. If class_name is a defined class, it returns TRUE, otherwise it returns FALSE.

Parameter

Serial numberParameters and descriptions
1

class_name(Required)

Class name.

2

autoload(Optional)

Whether to call __autoload by default.

Return value

If class_name is a defined class, it returns TRUE, otherwise it returns FALSE.

Online examples

The following is the usage of this function, to check if the class HelloWorld is defined-

<?php
   if (class_exists('HelloWorld')) {
      $helloworld = new HelloWorld();
   }
?>

   PHP Class/Object function reference manual