首頁 > 後端開發 > php教程 > Fatal error: Cannot access empty property

Fatal error: Cannot access empty property

WBOY
發布: 2016-06-06 20:14:02
原創
1403 人瀏覽過

代码整合如下:

<code><?php abstract class Model{
    protected $table = NULL;
    protected $db = NULL;
    public function __construct(){;
        var_dump(MySQL::getIns());
        $this->$db = MySQL::getIns();
    }
}

class catModel extends Model{
    protected $table = 'emec_cat';
    public function addCat($date){
      $sql = $this->db->Autoexpr($date);
      return $this->db->qurey($sql);
    }
} 

class MySQL {

        static protected $Ins;
        protected $res;



        static function getIns(){
            if(self::$Ins instanceof self){
                return self::$Ins;
        }
            self::$Ins = new MySQL();
            return self::$Ins;
        }

        private function __construct(){
            $this->res = 1;
        }

        protected function __destruct(){
            mysql_close($link);
        }
}

$date = array();
$date['cat_name'] = $_POST['cat_name'];
$date['parent_id'] = $_POST['parent_id'] + 0;
$date['intro'] = $_POST['intro'];
$catMode = new catModel();
$catMode->addCat($date);
 ?></code>
登入後複製
登入後複製

会出现:
Fatal error: Cannot access empty property in F:\Apache2.2\htdocs\emec\test.php on line 9
去掉基类的abstract问题依旧。
环境:
apache2.2 php5.3.5

回复内容:

代码整合如下:

<code><?php abstract class Model{
    protected $table = NULL;
    protected $db = NULL;
    public function __construct(){;
        var_dump(MySQL::getIns());
        $this->$db = MySQL::getIns();
    }
}

class catModel extends Model{
    protected $table = 'emec_cat';
    public function addCat($date){
      $sql = $this->db->Autoexpr($date);
      return $this->db->qurey($sql);
    }
} 

class MySQL {

        static protected $Ins;
        protected $res;



        static function getIns(){
            if(self::$Ins instanceof self){
                return self::$Ins;
        }
            self::$Ins = new MySQL();
            return self::$Ins;
        }

        private function __construct(){
            $this->res = 1;
        }

        protected function __destruct(){
            mysql_close($link);
        }
}

$date = array();
$date['cat_name'] = $_POST['cat_name'];
$date['parent_id'] = $_POST['parent_id'] + 0;
$date['intro'] = $_POST['intro'];
$catMode = new catModel();
$catMode->addCat($date);
 ?></code>
登入後複製
登入後複製

会出现:
Fatal error: Cannot access empty property in F:\Apache2.2\htdocs\emec\test.php on line 9
去掉基类的abstract问题依旧。
环境:
apache2.2 php5.3.5

写多了一个$

相關標籤:
php
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板