调用新类并发送要构造的数据


Calling new class and send data to construct

标题说明了一切。我对动态调用类有问题。我的主控制器正在获取一个包含所有需要加载的组件的数组。这是我的代码

public function generateViews($views) {
    $this->getView('header');
    $this->getView('footer');
    //echo $this->header;
    foreach ($views as $components) {
        include_once "Application/" . $components['folder'] . $components['name'] . "/" . $components['name'] . "_Controller.php";
        $this->{$components['name']} = new $components['name'];
        //echo $this->{$components['name']}->view;
    }
    //echo $this->footer;
}

问题是我的函数调用foreach中的新类。但是我不能将类的数据提供给构造。$this->{$components['name']} = new $components['name']($extradata, true, false);

有没有任何方法可以在不调用硬编码类的情况下将数据提供给构造?

我有一个解决方案。

$item = $components['name']';
$this->{$components['name']} = new $item(true,false);