-1
class MyAppClass {
protected $_config = array();
protected $_template = '';
public function init(){
require_once('core_config.php'); // Inside is $_SC_config with an array of values
$this->_config = $_SC_config;
$this->_template = new template;
echo $this->_template->echo_base();
}
}
class template extends MyAppClass{
public function echo_base() {
var_dump($this->_config); // returns empty array
}
}
$myApp = new MyAppClass;
$myApp->init();
這有什麼錯碼的上方,從而擴展類獲取父母的變量只是初始值
的var_dump($本 - > _配置)
在模板類初始化函數後返回空數組?
在此先感謝。
爲什麼應該有價值? –
您正在'init'內創建一個新的模板實例,它本身並沒有被初始化。你的類層次結構可能需要一些思考。 – iainn
這根本不是繼承的工作原理。 – deceze