1
以下代碼在PHP 5.3中導致「不推薦」錯誤...是否有替代品?在PHP 5.3中導致「不推薦」錯誤的PHP代碼
$this->widgets[$widget_class] = & new $widget_class();
以下代碼在PHP 5.3中導致「不推薦」錯誤...是否有替代品?在PHP 5.3中導致「不推薦」錯誤的PHP代碼
$this->widgets[$widget_class] = & new $widget_class();
這會是很好,如果你可以指定該錯誤消息說的話究竟,但我猜它是通知您通過引用,對象分配(=&
)已被棄用。對象爲總是從PHP 5開始分配並通過引用引用,因此包括&
是不必要的。簡單地刪除參考運算符:
$this->widgets[$widget_class] = new $widget_class();
我不認爲「通過引用賦值」一般不推薦使用,但「新對象」賦值是。請參閱http://php.net/manual/en/migration53.deprecated.php - *「現在不建議使用新引用來指定返回值。」* – Phil 2010-10-27 04:10:12
@Phil良好的鏈接,我正在尋找一個參考(無雙關語意圖)在手冊中,但找不到一個。 – deceze 2010-10-27 04:19:49
同樣,不得不使用谷歌,因爲我不認爲在遷移部分 – Phil 2010-10-27 04:23:10