簡體   English   中英

FatalThrowableError-在null上調用成員函數getStatusCode()

[英]FatalThrowableError - Call to a member function getStatusCode() on null

救命?

上次測試此功能時,它可以正常工作,但是由於某種原因,當我現在對其進行測試時,它是否會返回此錯誤?

我使用以下命令調用函數:

public function createPayment($uid,$api_uid,$limit)
{
        $api = new CallFunction();
        $result = $api->pay($uid,$api_uid,$limit);
}

這是我的CallFunction腳本:

 public  function pay(string $userid, string $apiuid, int $limiteos)
    {
       $client = null;

       $api_key = "api_key";
       $url = "http://www.payment.com/payment/order";

        $client = new Client();
        try
        {

            $data = ['method'=>'create', 'user_id' => $userid, 'api_uid' => $apiuid, 'limit_eos_count' => $limiteos, 'api_key' => $api_key];
            $response = $client->post($url, ['query' => $data]);
            $result = json_decode($response->getBody()->getContents());
            return $result;
           // $this->accessToken = $result->access_token;
        }
        catch (RequestException $e)
        {
           // var_dump($e);
            $response = $this->StatusCodeHandling($e);
            return 0;
          //  echo "error";
        }
    }

錯誤指向代碼的這一部分:

$response = $this->StatusCodeHandling($e);

我的StatusCodeHandling部分是這樣的:

public function StatusCodeHandling($e)
    {
        if ($e->getResponse()->getStatusCode() == '400')
        {
        $this->prepare_access_token();
        }
        elseif ($e->getResponse()->getStatusCode() == '422')
        {
    }

錯誤顯示了這一行:

if ($e->getResponse()->getStatusCode() == '400')

我現在很難調試。 前幾天在工作嗎? 如果我錯了,請多多注意!

我仔細檢查了我的鏈接。 事實證明,我的鏈接中有錯字,這就是為什么請求返回NULL的原因。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM