php构造函数类传递对象

时间:2017-04-15 13:24:16

标签: php class

好的,我完全改变了这个问题。尽量不要提供所有信息。但足以看出你是否能发现问题。

DB class。

class dbHandler {
    private $dbConn;
    private $config;
    private $cwd;

    public function  __construct()
    {
        $this->cwd = $_SERVER['DOCUMENT_ROOT'].'/ccrm';
        $this->config = parse_ini_file($this->cwd.'/../../glossary.config.ini'); // -- for local

        require_once('_mssql.php');
        require_once('_mysql.php');
    }

词汇表课程

class glossaryHandler {

    private $dbHandler;
    private $cwd;
    // this is the constructor this constructor runs on creation of object
    public function  __construct($db)
    {
        $this->dbHandler = $db;
    }

包含的文件(header.php)

require_once($cwd.'/resources/php/_dbHandler.php');
    $db = new dbHandler;
require_once($cwd.'/resources/php/_glossaryHandler.php');
$glossaryHandler = new glossaryHandler($db);

给出错误

注意:未定义的变量:db

0 个答案:

没有答案