我有一個ChildClass
,擴展爲ParentClass
。 ParentClass
有一個構造函數,它帶有兩個參數__construct('value2', ParentClass::COMMON)
。 HOwever我試圖從子類中調用繼承的newSelect()
方法。到目前爲止它還沒有成功。我如何從ChildClass
撥打NewSelect()
?也有可能,即使ParentClass
有一個構造函數需要兩個參數?在子類中訪問父級方法的正確方法
家長
class ParentClass {
const COMMON = 'common';
protected $db;
protected $common = false;
protected $quotes = array(
'Common' => array('"', '"'),
'Value2' => array('`', '`'),
'Value3' => array('`', '`'),
'Value4' => array('`', '`'),
);
protected $quote_name_prefix;
protected $quote_name_suffix;
public function __construct($db, $common = null) {
$this->db = ucfirst(strtolower($db));
$this->common = ($common === self::COMMON);
$this->quote_name_prefix = $this->quotes[$this->db][0];
$this->quote_name_suffix = $this->quotes[$this->db][1];
}
public function newSelect() {
return $this->newInstance('Select');
}
protected function newInstance($query) {
//Some more code, not relevant to example
}
}
兒童
class ChildClass extends ParentClass {
public function __construct() {
}
// Call the inherited method
private $_select = Parent::newSelect();
// Do something with it
}
您是否收到任何錯誤或發生了什麼? – 2014-12-05 19:47:13
@u_mulder是的,'解析錯誤:語法錯誤,意外'(',期待','或';''或者如果我在子類中創建一個與'new'對象我得到'解析錯誤:語法錯誤,意外'new''。 – 2014-12-05 19:49:11
語法錯誤發生在某些行上,究竟是什麼行以及這些行上的代碼是什麼? – 2014-12-05 19:54:01