I have a strange issue where I set values in a parent class but cannot access those values in a child class extending the parent.
class Parent
{
protected $config;
public function load($app)
{
$this->_config();
$this->_load($app);
}
private function _config()
{
$this->config = $config; //this holds the config values
}
private function _load($app)
{
$app = new $app();
$this->index;
}
}
class Child extends Parent
{
public function index()
{
print_r($this->config); // returns an empty array
}
}
$test = new Parent();
$test->load('app');
when I do that i get an empty array printed out. But if I do this then I am able to access those config values.
private function _load($app)
{
$app = new $app();
$app->config = $this->config
$app->index;
}
and
class Child extends Parent
{
public $config;
....
}
then I can access the config data from the parent.
You are accessing the values before anything is initialized there. First you have to set the values.
Example: call a method is the parent class, which set the value, on the contructor of the child class.
Update: You also seem to confused about concept of OOP
But, you have to work with parent methods and properties just the same way you would do in the normal object.
Lets See another example:
But another example