【发布时间】:2016-06-22 15:10:56
【问题描述】:
所以我在主类中有这种结构函数
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 的这种方法不起作用,请告诉我如何检查类是否存在于文件中的正确方法。谢谢
【问题讨论】:
-
PHP 有一个实际上叫做
class_exists()的函数这一事实有什么讽刺意味吗? php.net/manual/en/function.class-exists.php ...我几乎可以保证,如果您刚刚在中输入了您的问题标题,您就会得到这个答案,并为自己节省了大量的时间来写出问题。