【发布时间】:2012-07-28 05:46:10
【问题描述】:
我想创建一个博客,这是控制器文件但我不明白这一行
$this->$model =& new $model;
这条线做什么?
protected $_model;
protected $_controller;
protected $_action;
protected $_template;
function __construct($model, $controller, $action) {
$this->_controller = $controller;
$this->_action = $action;
$this->_model = $model;
$this->$model =& new $model;
$this->_template =& new Template($controller,$action);
}
function set($name,$value) {
$this->_template->set($name,$value);
}
function __destruct() {
$this->_template->render();
}
}
【问题讨论】:
-
我认为这个问题不应该重复关闭。除了
&,这个问题还有其他组成部分。>$,new $很感兴趣。 -
从 PHP 5.x 开始,不建议在处理对象时使用
=&。您看到的任何使用它的代码都表明它仍在使用旧的 PHP4.x 思维方式。由于弄乱了引用计数,它会导致内存泄漏。另外,仅供参考,MVC 中的模型不是一个类,而是一个层。