PHP class_exists() function
This function is used to check whether the class name is exist or not.
Syntax
class_exists(classname);
It takes the class name as parameter and returns a boolean value. It returns true if the class is already exists and false if it does not exist.
Example1
<?php
class Demo {
function welcome(){
echo 'Hello World';
}
}
if(class_exists(Demo)) {
$obj = new Demo();
$obj->welcome();
}
else{
echo 'Class is not defined.';
}
?>
Output :
Hello WorldExample2
<?php
if(class_exists(Student)) {
$obj = new Student();
$obj->welcome();
}
else{
echo 'Class is not defined.';
}
?>
Output :
Class is not defined.Related PHP Functions
PHP array_reverse() functionPHP array_diff() function
PHP array_key_exists() function
PHP array_push() function
PHP array_search() function
PHP class_exists() function
PHP curl_setopt() function
PHP die() function
PHP dirname() function
PHP each() function
PHP explode() function
PHP file_exists() function
PHP function_exists() function
PHP getenv() function
PHP is_readable() function
PHP ksort() function
PHP mkdir() function
PHP ob_start() function
PHP parse_url() function
PHP str_repeat() function
PHP substr() function