class_exists() function in PHP


The class_exists() function in PHP checks if the class has been defined. It returns TRUE if class is a defined class, else it returns FALSE.

Syntax

class_exists(class, autoload)

Parameters

  • class − Name of the class.

  • autoload − Whether to call __autoload or not by default

Return

The class_exists() function returns TRUE if class is a defined class, else it returns FALSE.

Example

The following is an example −

 Live Demo

<?php
if (class_exists('Demo')) {
   $demo = new Demo();
   echo "Our class!";
} else {
   echo "Class does not exist";
}
?>

Output

The following is the output −

Class does not exist!

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 24-Jun-2020

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements