【发布时间】:2012-11-12 09:28:37
【问题描述】:
我正在使用this tutorial学习PHP MVC。在那里我发现了以下特殊符号 用于对象初始化
$this->$model =& new $model;
我知道 & 用于在 HTML 中表示 & 符号。这里是什么意思?下面给出了符号所在的类。还有那个教程呢?它是一个好的吗?如果没有,有人可以推荐我一个更好的吗?
<?php
class Controller {
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();
}
}
【问题讨论】:
-
在我看来这不是有效的 PHP。运行时是否会产生任何错误或警告?
-
请找到更好的教程。
$variable =& new Something是 PHP 4 的遗留物,在 PHP 5 中不需要。mysql_*函数已弃用,不应在新代码中使用。register_globals和magic_quotes_gpc之类的东西也是如此。 -
你能给我推荐一个好的教程吗?
-
由于您正在按照教程编写自己的 MVC 框架,因此我假设您对 PHP 有基本的了解。如果我的假设没有错的话,我建议你通过现有的 MVC 框架的源码来学习。一些很好的例子是
Fuel PHP和Slim PHP -
停止!那篇文章严重过时了! (超过 3 年前!)Please, don't use
mysql_*functions in new code。它们不再维护,deprecation process 已开始使用。看到red box?改为了解prepared statements,并使用PDO 或MySQLi - this article 将帮助您决定哪个。如果你选择 PDO,here is a good tutorial.
标签: php reference variable-assignment