Okay my goal is to build a Parent with functions to be used in children.
When a child calls a parent class the instance in that parent::method should be made of the child itself and not the parent.
Can you help?
<?php
class test {
protected function set($array = array('1','parent')) {
$this->id = $array[0];
$this->name = $array[1];
}
protected function get() {
return get_object_vars($this);
}
public function show() {
$this->set();
return $this->get();
}
protected function find_by_id() {
$row = array(array("id" => "igoreee"),array("id" => "max"));
$object_array= array();
foreach($row as $record):
$object_array[] = $this->instantiate($record);
endforeach;
return $object_array;
}
protected function instantiate($record) {
// Could check that $record exists and is an array
foreach ($record as $attribute => $value):
if ($this->has_attribute($attribute)) {
$this->$attribute = $value;
}
endforeach;
return $this->attributes();
}
private function has_attribute($attribute) {
// get_object_vars returns an associative array with all attributes
// excluding static vars
$object_vars = $this->attributes();
return array_key_exists($attribute, $object_vars);
}
protected function attributes() {
// return an array of attribute keys and their values
return get_object_vars($this);
}
}
class more extends test {
private $id = '1';
private $name = '2';
public function set_more() {
$array = array('2','child');
parent::set($array);
return parent::get();
}
public function get_mores_objects() {
return parent::find_by_id();
}
}
$a = new more;
print_r($a->get_mores_objects());
print '<br />';
?>
if i put private $id in parent I will get back the parents properties but I want to get the child properties instead....