简体   繁体   English

PHP致命错误:在Lumen 5.2的写入上下文中无法使用方法返回值

[英]PHP Fatal error: Can't use method return value in write context in Lumen 5.2

I got error when I try to run the following code Error I am getting. 当我尝试运行以下代码时出现错误。 Fatal error: Can't use method return value in write context in Lumen 5.2.

In My Route : 在我的路线中:

$app->post('oauth/access_token', function(Request $request) {

        $userverify=User::Where('username',$_POST['username'])->orWhere('email',$_POST['username'])->first();


        if($userverify){

             $request->input('username')=$userverify->email;                

        }  


        $json = array();
        try{
            $json = Authorizer::issueAccessToken();
        }catch (Exception $e){
            $json['error'] = 'invalid_credentials';
            $json['error_description'] = 'The user credentials were incorrect';
        }

        return response()->json($json);
    });

Thanks beforehand. 预先感谢。

This error is because you're assigning a value to a function's return statement right here: 该错误是因为您正在此处为函数的return语句分配值:

$request->input('username') = $userverify->email;

$request->input() is used to only retrieve the request values and not to set them. $ request-> input()仅用于检索请求值,而不用于设置它们。

If you still want to add some values to the request, then you might try using the following approach: 如果您仍想向请求中添加一些值,则可以尝试使用以下方法:

// Add a value to the request
$request->request->add(['username' => $userverify->email]);

// Set a value in request
$request->request->set('username', $userverify->email);

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM