php 判断类是否包含方法,php中如何使用class_exists判断类是否存在 PHP method_exists检查类的方法是否存在...

[php]

require APP_ROOT_PATH.FOLDER_NAME.’/Lib/’.APP_TYPE.’/core/MainBaseModule.class.php’;

require APP_ROOT_PATH.FOLDER_NAME.’/Lib/’.APP_TYPE.’/core/main_init.php’;

require APP_ROOT_PATH.FOLDER_NAME.’/Lib/page.php’;

define("CTL",’ctl’);

define("ACT",’act’);

class MainApp{

private $module_obj;

//网站项目构造

public function __construct(){

if($GLOBALS[‘pay_req’][CTL])

$_REQUEST[CTL] = $GLOBALS[‘pay_req’][CTL];

if($GLOBALS[‘pay_req’][ACT])

$_REQUEST[ACT] = $GLOBALS[‘pay_req’][ACT];

$module = strtolower($_REQUEST[CTL]?$_REQUEST[CTL]:"index");

$action = strtolower($_REQUEST[ACT]?$_REQUEST[ACT]:"index");

$module=MODULE_PREFIX.$module;

$module = filter_ctl_act_req($module);

$action = filter_ctl_act_req($action);

/*判断文件是否存在*/

if(!file_exists(APP_ROOT_PATH.FOLDER_NAME."/Lib/".APP_TYPE."/".$module."Module.class.php"))

$module = "index";

require_once APP_ROOT_PATH.FOLDER_NAME."/Lib/".APP_TYPE."/".$module."Module.class.php";

/*判断类是否存在*/

if(!class_exists($module."Module"))

{

$module = "index";

require_once APP_ROOT_PATH.FOLDER_NAME."/Lib/".APP_TYPE."/".$module."Module.class.php";

}

/*判断方法是否存在*/

if(!method_exists($module."Module",$action))

$action = "index";

define("MODULE_NAME",$module);

define("ACTION_NAME",$action);

$module_name = $module."Module";

$this->module_obj = new $module_name;

$this->module_obj->$action();

}

public function __destruct()

{

unset($this);

}

}

?>

[/php]

说明

布尔 method_exists (对象 $对象 ,字符串 $ METHOD_NAME )

如果METHOD_NAME 所指的方法在对象 所指的对象类中已定义,则返回TRUE,否则返回FALSE。

【举例】#1 method_exists()例子

$directory = new Directory('.');

var_dump(method_exists($directory,'read'));

?>

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值