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 very useful for judging the existence of classes automatically loaded and classes before class instantiation.
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 very useful for judging the existence of classes automatically loaded and classes before class instantiation.
This article analyzes the usage of the php function class_exists to determine whether a 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.
,