我有一个这样的主类结构函数:
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/zh/function.class-exists.php。如果你将这个问题作为标题在搜索引擎上搜索,我几乎可以保证你会得到这个答案,并且节省大量时间来撰写问题。 - CD001