Check if a class exists in PHP
To check whether a class exists or not in PHP, you need to use the class_exists() function.
Call the class_exists() function and pass the class name as a string parameter to that function:
// ๐ check if a class named Human exists
class_exists("Human");
The function will return either true or false. Combine it with an if block to create conditional branch as shown below:
if(class_exists("Human")){
print "The Human class exists";
} else {
print "Class does not exists";
}
And that’s how you check whether a class exists or not in PHP. Nice! ๐
More PHP tutorials
See allPHP
PHP form validation basic example
Dec 22, 2022
PHP
PHP validate email address (with code examples)
Dec 22, 2022
PHP
How to redirect using PHP with code examples
Dec 22, 2022
PHP
Handling form data using PHP (GET and POST)
Dec 21, 2022
PHP
How to fix Wordpress PHP error missing MySQL extension
Dec 21, 2022