PHP | class_exists() Function Last Updated : 27 Apr, 2020 Comments Improve Suggest changes Like Article Like Report The class_exists() function is an inbuilt function in PHP which is used to check whether the given class is defined or not. Syntax: bool class_exists( string $class_name, bool $autoload = TRUE ) Parameters: This function accept two parameters as mentioned above and described below: $class_name: It holds the class name which need to check their existence. $autoload: It checks whether the __autoload is called or not by default. Return Value: This function returns True if class name is defined otherwise returns False. Below programs illustrate the class_exists() function in PHP: Program 1: php <?php // Create a class class GFG { public $Geek_name = "Welcome to GeeksforGeeks"; } // Check class name exist or not if(class_exists('GFG')) { echo "Class name exists"; } else { echo "Class name does not exist"; } ?> Output: Class name exists Program 2: php <?php // Creating class class GFG { public $data1; public $data2; public $data3; } if(class_exists('GFG')) { // Creating an object $obj = new GFG(); // Set values of $obj object $obj->data1 = "Geeks"; $obj->data2 = "for"; $obj->data3 = "Geeks"; // Print values of $obj object echo "$obj->data1 \n$obj->data2 \n$obj->data3"; } else { echo "Class does not exist"; } ?> Output: Geeks for Geeks Reference: https://www.php.net/manual/en/function.class-exists.php Create Quiz Comment A ashokjaiswal Follow 0 Improve A ashokjaiswal Follow 0 Improve Article Tags : Web Technologies PHP PHP-function PHP-OOP Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like