Home  >  Article  >  Backend Development  >  PHP determines whether a class exists function class_exists

PHP determines whether a class exists function class_exists

高洛峰
高洛峰Original
2016-11-29 15:05:251187browse

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 ] )

Whether this function The given class is defined and checked, returning true if class_name is a defined class, otherwise returning false.

php example code is as follows:

if (class_exists('myclass')) {

$myclass = new myclass( );

}

function __autoload($class)

{

include($class . '.php');

if ( !class_exists($class, false)) {

                                                                                                                                                                                                                                                  !

$ myclass = new myclass();

}//Open source code phpfensi.com

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
Previous article:php feof functionNext article:php feof function