2012-05-29 22 views

回答

6

刪除&之前$this

PHP5不需要所加 - 所有對象作爲默認對象標識符通過,沒有必要,因爲它是必需的PHP 4

+0

@hakre好編輯,謝謝 – damianb

3

通過參考與通過模仿這種爲了通過在參考傳遞變量php5你需要在你的函數聲明上有&。不是在您調用該功能時。

function call_user_func($param1, &$param2) { 
    // $param2 will be a reference 
    // as mentioned by damianb though objects are by default references 
    // http://php.net/manual/en/language.oop5.references.php 

} 

當調用這只是傳遞你的參數爲正常和param2將通過引用傳遞。

http://php.net/manual/en/language.references.pass.php

上述鏈路clearely解釋了錯誤。

注:有一個函數調用無符號 - 只有函數定義 。單獨的函數定義足以通過引用正確地傳遞參數 。從PHP 5.3.0開始,當您在foo(& $ a);中使用& 時,您將收到警告 ,聲稱「不需要通過呼叫時傳遞」。