Skip to content
This repository has been archived by the owner on Jan 22, 2021. It is now read-only.

array_key_exists() expects parameter 2 to be array, null given #279

Open
Dadibom opened this issue May 29, 2018 · 4 comments
Open

array_key_exists() expects parameter 2 to be array, null given #279

Dadibom opened this issue May 29, 2018 · 4 comments

Comments

@Dadibom
Copy link

Dadibom commented May 29, 2018

Latest release sometimes gives the following error:
array_key_exists() expects parameter 2 to be array, null given in Client.php (line 125)

the function fillInvoiceData receives null as its second parameter as $data = $body['data']; is null on line 206 (createInvoice)

@pieterpoorthuis
Copy link

When creating an invoice, either an error message or data has to be returned by BitPay.

Can you explain when this happens? Because if no data is returned, invoice creation fails and an error should be thrown as well.

@petski
Copy link

petski commented Jun 8, 2018

Just a comment to confirm this bug report. Had a couple of these between 07-Jun-2018 21:59:21 (CEST) and 07-Jun-2018 22:15:42 (CEST).

My theory is that the server returned a non-200 response, with which the code doesn't take care of in src/Bitpay/Client/Adapter/CurlAdapter.php::sendRequest()

I normally do something like this:

$res = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = $curl_errno ? curl_error($ch) : null;
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($res === false) {
  throw new ...
}

if ($status_code != 200) {
  throw new ...
}

.. etc etc

@Dadibom
Copy link
Author

Dadibom commented Jun 8, 2018

Sorry, forgot to respond. I don't know what causes this. It's only happened at one point for me (not personally, i found the error in my logs), a couple of attempts in a row.

@peter279k
Copy link

To prevent this error, I think we can check the $data is array type or casting this to array type before passing to the array_key_exists function.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants