ここに私のクラスの例があります。コンストラクタにデフォルトオプションが定義されており、提供されているオプションに置き換えたいと思います。ArrayコンストラクタでPHPを置き換えます
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();
オプションの内容を印刷すると、置き換えなくてもデフォルト値が得られます。 私は何が間違っていますか?
あなたはタイプミスがあります( 'array_replace(_recursive)はarray_replace_recursiveでなければなりません) –