-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関数の後に空の配列を返します。 ?
ありがとうございます。
なぜ価値があるはずですか? –
'init'の内部に新しいテンプレートインスタンスを作成していますが、それ自体は初期化されていません。あなたのクラス階層にはいくつかの考えが必要かもしれません。 – iainn
これは継承の仕組みではありません。 – deceze