2014-11-23 51 views
2

我收到無法在寫入上下文中使用函數返回值錯誤430行中的代碼中,但我無法理解爲什麼我是收到此錯誤..無法在寫入上下文中使用函數返回值Laravel 4

奇怪的是,我只得到了服務器上的這個錯誤(PHP 5.3),而不是在我的本地(PHP 5.5.10)

return Redirect::route('account-activate-user', (empty(Input::get('code'))) ? '{code}' : e(Input::get('code'))) 
     ->with('global', 'De activatie-code is niet geldig.'); 

沒有人有解決這個問題?

回答

3

它是因爲你使用empty()而歸函數的值(Input::get()),當它只接受一個變量。考慮如何Input::get()作品,即你可以傳遞第二個參數作爲默認時沒有設置輸入,可以完全跳過empty()檢查,只需使用:

return Redirect::route('account-activate-user', Input::get('code', '{code}')) 
     ->with('global', 'De activatie-code is niet geldig.'); 

,或者更接近你的代碼:

return Redirect::route('account-activate-user', (Input::has('code') ? '{code}' : e(Input::get('code'))) 
     ->with('global', 'De activatie-code is niet geldig.'); 
1

在PHP5.5之前,函數empty()不能接受返回值。

這意味着Input::get('code')返回一個值,並且此值不能傳遞給empty()函數。

雖然不是最好的解決方案,您可以快速解決這一問題的方法:但是這裏

$inputCode = Input::get('code'); 

return Redirect::route('account-activate-user', (empty($inputCode)) ? '{code}' : e($inputCode)) 
->with('global', 'De activatie-code is niet geldig.'); 

你可以找到副本:

Can't use function return value in write context?

1

我得到了同樣的錯誤和更新PHP版本到5.5.x修復了我。

相關問題