This would be quite a change, but I think it would be really useful. You almost always need to set certain values when creating a new object, e.g instead of:
$model = new User("myScenario");
$model->name = "My Name";
$model->address = "123 Fake Street";
$model->city = "Springfield";
It would be much nicer to be able to do:
$model = new User(array(
"scenario" => "myScenario",
"name" => "My Name",
"address" => "123 Fake Street",
"city" => "Springfield"
));
So in the new Yii\Component class
public function __construct($config = null)
{
if ($config!==null)
$this->configure($config);
}
public function configure($config)
{
if(is_string($config))
$config=require(Yii::getPathOfAlias($config).'.php');
if(is_array($config))
{
foreach($config as $name=>$value)
$this->$name=$value;
}
}
If this is unacceptable for some reason, I think we should at the very least make configure() part of Yii\Component because it’s such a common use case.