php determines whether a class exists function class_exists usage analysis, function class_exists
This article analyzes the usage of function class_exists in PHP to determine whether a class exists. Share it with everyone for your reference. The details are as follows:
If we want to judge whether a class can be used, we can first use the class_exists function to judge. Let’s look at a few examples.
bool class_exists ( string $class_name [, bool $autoload = true ] )
This function checks whether the given class is defined. this function checks whether or not the given class has been defined.
Returns true if class_name is a defined class, false otherwise.
Examples are as follows:
Copy code 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 be helpful to everyone’s PHP programming design.
http://www.bkjia.com/PHPjc/911905.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/911905.htmlTechArticlePHP determines whether a class exists function class_exists usage analysis, function class_exists This article example analyzes the php determine whether a class exists function class_exists usage analysis . Share it with everyone for your reference. Tool...