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 −
<?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!