This article mainly introduces the usage of the class_exists function in php to determine whether a class exists, and analyzes the application of PHP to determine whether a class exists, it is of practical value for judging the existence of classes before automatic loading and class instantiation. if you need it, you can refer to the examples in this article to analyze the usage of php to determine whether the class has the function class_exists. Share it with you for your reference. The details are as follows:
If we want to determine whether a class can be used, we can use the class_exists function to determine whether a class can be used. Here are several examples.
Bool class_exists (string $ class_name [, bool $ autoload = true])
Whether the class specified by this function is defined and checked. This function checks whether or not the given class has been defined.
Returns true. if class_name is a defined class, otherwise, false is returned.
Example:
The code is as follows:
Function _ autoload ($ class)
{
Include ($ class. '. php ');
// Check to see whether the include declared the class
If (! Class_exists ($ class, false )){
Trigger_error ("unable to load class: $ class", e_user_warning );
}
}
If (class_exists ('myclass ')){
$ Myclass = new myclass ();
}
I hope this article will help you with PHP programming.