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

本文实例分析了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程序设计有所帮助。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值