所以我在主类中有这种结构函数
function __construct(){
$this->conf = $GLOBALS['conf'];
$this->dbi = new dbinfo;
$this->modOpt = new modOptions;
$this->lang = new language;
/** Connect DB extended Class **/
parent::__construct($GLOBALS['connect']);
}
我在其中定义类,但此类位于库文件中,该库文件包含在文件开头,除了一个类之外,该类在发布请求出现时包含在内,如下所示:
if (isset($_POST['delGroup']) && isset($_SESSION['content_viewer']) && $_SESSION['content_viewer']['code'] >= 1){
include_once(realpath(dirname(__FILE__) . '/../..')."/mod/dbinfo/proc.php");
}
所以我想像这样在 dbinfo 类的构造函数中添加检查
function __construct(){
$this->conf = $GLOBALS['conf'];
if (isset(new dbinfo))
$this->dbi = new dbinfo;
$this->modOpt = new modOptions;
$this->lang = new language;
/** Connect DB extended Class **/
parent::__construct($GLOBALS['connect']);
}
但这个方法与if isset
不起作用,请告诉我如何检查文件中是否存在类的正确方法。谢谢
尝试使用,class_exists()
http://php.net/manual/en/function.class-exists.php
在你的情况下,寻找dbinfo
类这样做:
if(class_exists('dbinfo')){
//do something
如果您的类有命名空间,请包含完整的命名空间类名。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)