PHP determines whether a class exists function class_exists

高洛峰
Release: 2016-11-29 15:05:25
Original
1216 people have browsed it

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

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template