Here is an example of my class, I have default options defined in the constructor and I want to replace them with any options provided.
class Class{
private $options;
function __construct($options=null){
$this->options = array('option1'=>'value', 'option2'=>'value', ...);
array_replace(_recursive)($this->options,$options);
}
function showOpts(){
print_r($this->options);
}
}
$opt = array('newOpt'=>value ..);
$c = new Class($opt);
$c->showOpts();
when I print the contents of options I get the default values without any replacement.
What am I doing wrong?
Because array_replace_recursive returns the resulting array.
You should assign its result to $this->options