这篇文章主要介绍了php判断类是否存在函数class_exists用法,实例分析了PHP针对类是否存在进行判断的应用,对于自动加载类以及类实例化之前的存在判断来说都非常具
本文实例分析了php判断类是否存在函数class_exists用法。分享给大家供大家参考。具体如下:
如果我们要判断一个类是不是可以用,可以先使用class_exists函数来判断一下,下面来看几个例子。
bool class_exists ( string $class_name [, bool $autoload = true ] )
此功能是否给定的类被定义检查。this function checks whether or not the given class has been defined.
返回true,如果class_name是一个定义的类,否则返回false。
实例如下:
复制代码 代码如下:
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();
}
希望本文所述对大家的PHP程序设计有所帮助。
,
Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download
The most popular open source editor

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 English version
Recommended: Win version, supports code prompts!
