2013-05-29 23 views
0


我知道這個問題已經被回答了很多次,但是我有一些問題我無法修復。

我收到了幾條關於在特定頁面和特定行上分配返回值的警告。但是,當我OPET該頁面,無論是請求的線是空的,下面的評論或別的東西.. 這裏是一個警告,網頁代碼與它去:棄用:通過引用分配新的返回值在代碼的空行上被棄用

Deprecated: Assigning the return value of new by reference is deprecated in /home/saltushr/public_html/_classes/hr/dimedia/framework/Controller.class.php on line 25

Deprecated: Assigning the return value of new by reference is deprecated in /home/saltushr/public_html/_classes/hr/dimedia/framework/Controller.class.php on line 26

和代碼是:

<?php 
/** 
* This clas instantiates the required {@link Model} and {@link View} objects. 
* 
* @author Berislav Lopac [email protected] 
* @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 $model;
22
23 var $view;
24
25
26

27 /**

誰能幫助我明白這是什麼一回事呢?我在理解PHP方面很新,可以使用一些幫助。 謝謝。

+0

哦,我在格式化代碼後搞砸了行號引用......但是很多空行都很糟糕。 –

+0

在使用參考資料之前,您應該閱讀本手冊:http://php.net/references – Daniel

+0

我知道,問題在於此代碼不是我的..我只是想刪除已棄用的警告。我完成了3頁,但這是一個竊聽我。 @Felix Kling,刪除空行,我會盡早做到這一點。只有一個問題,當我改變我得到的代碼時: 解析錯誤:語法錯誤,意外的T_CLASS位於/home/saltushr/public_html/_classes/hr/dimedia/framework/Controller.class.php第1行 ...即使當我只複製上面的代碼沒有額外的空行.. – ecoLogic

回答

1

變化

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

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

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

$this->view =new $view($this->model); 
+0

我知道這一點,但是當我對該代碼行進行更改時,我得到了有關同一頁面的新錯誤: 解析錯誤:語法錯誤,/ home/saltushr/public_html/_classes中意外的T_CLASS /hr/dimedia/framework/Controller.class.php在線1 我已經讀過它有methin與丟失「}」或一些其他錯誤,但我找不到任何東西.. – ecoLogic

1

您分配一個新的實例作爲參考,在設計這不是一個很好的解決方案。相反,只要對象請求特定資源(例如,您的getView方法),就將對象作爲參考傳遞。

一些對象必須保存初始實例。

相關問題