php - Extended class gets only initial value of parent's variable -
class myappclass { protected $_config = array(); protected $_template = ''; public function init( ){ require_once('core_config.php'); // inside $_sc_config 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();
what's wrong code above
var_dump($this->_config)
in template class returns empty array after init function?
thanks in advance.
i think don't object programming yet. in myappclass::init
method create new object of template
class extends myappclass
class. have no idea want acheve show snippet works.
<?php class myappclass { protected $_config = array(); protected $_template = ''; protected function init( ){ //require_once('core_config.php'); // inside $_sc_config array of values $this->_config = 'foo'; } } class template extends myappclass{ public function __construct(){ $this->init(); } public function echo_base() { var_dump($this->_config); // returns empty array } } $myapp = new template; $myapp->echo_base();
wiki
Comments
Post a Comment