다음은 클래스의 예입니다. 생성자에서 정의 된 기본 옵션이 있으며 제공되는 옵션으로 대체하려고합니다.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이어야 함). –