找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1331|回复: 0
打印 上一主题 下一主题

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

[复制链接]

2560

主题

2560

帖子

7622

积分

论坛元老

Rank: 8Rank: 8

积分
7622
跳转到指定楼层
楼主
发表于 2018-2-14 05:52:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

            本文实例分析了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。
实例如下:
[U]复制代码[/U] 代码如下: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 判断常量,变量和函数是否存在
  • php file_exists 检查文件或目录是否存在的函数
  • php !function_exists("T7FC56270E7A70FA81A5935B72EACBE29"))代码解密
  • PHP数组对比函数,存在交集则返回真,否则返回假
  • PHP strstr 函数判断字符串是否否存在的实例代码
  • php使用function_exists判断函数可用的方法
  • PHP使用get_headers函数判断远程文件是否存在的方法
  • php通过function_exists检测函数是否存在的方法
            
  • 分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    用户反馈
    客户端