因此,在第一部分中,我制作了2个对象,实例化了两个类(我们从createController函数生成的一个类)
$loader = new Loader();
$controller = $loader->createController();
$controller->executeAction();
public function executeAction() {
return $this->{$this->action}();
}
我的问题是采用以下代码行:$this-> {$this-> action}()此方法的调用方式以及为什么使用花括号;试图执行action();扩展类的功能呢?
解决方法:
$this->{$this->action}();
$this->action = 'func1';
$this->{$this->action}();
等效于:
$this->func1();
有关更多示例,请参见PHP文档variable variables和variable functions.需要大括号是因为$this-> $this-> action()通常被视为($this-> $this)-> action().