Home >Backend Development >PHP Tutorial >PHP determines whether a class exists function class_exists usage analysis, function class_exists_PHP tutorial

PHP determines whether a class exists function class_exists usage analysis, function class_exists_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:14:08753browse

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.

www.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...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn