php判断类是否存在函数class_exists用法分析

yipeiwu_com6年前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程序设计有所帮助。

相关文章

用PHP伪造referer突破网盘禁止外连的代码

比如我放纳米盘里的文件http://img.namipan.com/downfile/da333ee178bdad6531d1ec1540cf86277c116b6300887600/0...

使用php统计字符串中中英文字符的个数

复制代码 代码如下:<?phpecho $str = "43fdf测试fdsfadaf43543543职工问防盗锁防盗锁5345gfdgd";preg_match_all("/[0...

php文件上传简单实现方法

本文实例讲述了php文件上传的简单实现方法。分享给大家供大家参考。具体如下: 文件1:index.php 复制代码 代码如下:<form enctype="multipart/fo...

国外十大最流行的PHP框架排名

国外十大最流行的PHP框架排名

以下为十个目前最流行的基于MVC设计模式的PHP框架。 1. Yii Yii是一个基于组件的高性能的PHP的框架,用于开发大规模Web应用。Yii采用严格的OOP编写,并有着完善的库...

php防盗链的常用方法小结

1.简单防盗链 复制代码 代码如下: $ADMIN[defaulturl] = "http://jb51.net/404.htm";//盗链返回的地址 $okaysites = arra...