不推荐:不推荐在代码的空行中通过引用指定new的返回值


Deprecated: Assigning the return value of new by reference is deprecated on empty lines of code


我知道这个问题已经被回答了很多次,但我有一些问题无法解决

我收到了几个关于在特定页面和特定行上分配返回值的警告。但当我浏览该页面时,请求的行要么是空的,要么是在评论下,要么是其他什么。。这里有一个警告和相应的页面代码:

不推荐:通过引用指定new的返回值是中已弃用/home/saltushr/public_html/classes/hr/dimedia/framework/Controlle.class.php在线25

不推荐:通过引用指定new的返回值是中已弃用/home/saltushr/public_html/classes/hr/dimedia/framework/Controlle.class.php在线26

代码为:

<?php
/**
 * This clas instantiates the required {@link Model} and {@link View} objects.
 *
 * @author Berislav Lopac berislav.lopac@dimedia.hr 
 * @version 1.0
 */
class Controller {
    var $model;   
    var $view;
    /**
     * The constructor.
     * Instantiates the {@link Model} and {@link View} objects.
     *
     * @param $_task    A String setting the base name of the instantiated objects.
     * @param $_db      ADOConnection object containing the connection to the database.
     * @param $_input   An Array with the input values required by the Model (usually the $_REQUEST array).
     */
    function &Controller($_name, &$_db, $_input) {
        $model = $_name . "Model";
        $view  = $_name . "View";
        $this->model =& new $model($_db, $_input);
        $this->view  =& new $view($this->model);
    }
    /**
     * Returns the associated {@link View} object.
     * @return View
     */
    function &getView() {
        return $this->view;
    }
}
?>

正如你所看到的,第25行和第26行是空的:

21 var$模型
22
23 var$view
24
25
26

27/**

有人能帮我理解这是怎么回事吗?我对理解PHP还很陌生,可能需要一些帮助。谢谢

更改

$this->model =& new $model($_db, $_input);
$this->view  =& new $view($this->model);

$this->model =new $model($_db, $_input);
$this->view  =new $view($this->model);

您正在分配一个新实例作为引用,从设计上讲,这不是一个好的解决方案。相反,只要对象请求特定资源(例如getView方法(,就将对象作为引用传递。

某些对象必须包含初始实例。