I have two classes Foo and Bar that Bar extends Foo as below:
class Foo {
protected
$options = array(),
$defaults = array(1, 2);
public function __construct($options){
array_push($this->options, $this->defaults);
}
}
class Bar extends Foo {
protected $defaults = array(3, 4);
public function print(){
print_r($this->$options);
}
}
$bar = new Bar();
$bar->print();
i thought that result should be array(1,2,3,4) but is array(3,4).
how to solve that ?
edit
i don’t want Bar class to have constructor because i’m just implementer of superclass and don’t know what really will happen in child class.
There are a couple of solutions, the simplest would be a second variable to be used as an extended defaults, then merge the arrays.