I’m fairly new to Object Oriented Programming, but I’m learning slowly. Basically what I have here is a parent class that calls a child class’s method which is supposed to update the parent class’s array ($this->lang). However when I add more data to the array in the child class, the change doesn’t go through to the parent class.
[B][SIZE=”3″]Rough Example:
[code=php]
class ClassA
{
protected $array;
public function __construct
{
$this->array = array();
}
protected function init()
{
$class2 = new ClassB;
$class2->insert_into_array();
}
}
class ClassB extends ClassA
{
public function __construct()
{
parent::__construct();
}
protected function insert_into_array()
{
array_push($this->array, $database_entry);
}
}
$heyo = new ClassA;
$heyo->init();
/*
I’m writing this code directly into this post and don’t have time to check it over carefully,
but it gives you an idea of what I’m trying to accomplish.
*/
Now if I print_r the array in the child class’s insert_into_array() method, it shows up as expected. But if I print_r the array in the parent class’s init() method after calling the insert_into_array() method, it comes back empty.
So, the question is, how do I update the array in the parent class?