braintree / braintree_php

Braintree PHP library
https://developer.paypal.com/braintree/docs/start/overview
MIT License
547 stars 224 forks source link

PHP Warning: Undefined array key 0 in /vendor/braintree/braintree_php… #316

Closed simoheinonen closed 2 years ago

simoheinonen commented 2 years ago

…/lib/Braintree/ResourceCollection.php on line 58

Summary

Checklist

hollabaq86 commented 2 years ago

👋 @simoheinonen can you provide a little context behind this PR? What were you attempting to do when you received this error?

strix commented 2 years ago

@hollabaq86 I can attempt to answer for OP since I'm having the same issue:

On php 7.x, accessing an invalid index on an array returns null. In php 8.x, accessing an invalid index on an array still returns null but also outputs a warning.

You can test this on any php online | sandbox, by selecting php 7.x and then php 8.x with the following code:

$arr = [];
var_dump(isset($arr[0]));
var_dump($arr[0]); // outputs null in both php 7.x and php 8.x but a warning is emitted in php 8.x

The PR that @simoheinonen fixes this warning from ever being emitted without changing the result between php versions and I look forward to this getting merged in soon.

WalkerKarina commented 2 years ago

Hi @simoheinonen, thanks for the PR! We noticed there isn't any test coverage for this change, could I trouble you to add that? Please could you also mark the changelog entry as unreleased?

Epreuve commented 2 years ago

We released this as a fix in 6.9.0. If you encounter any issues in the future feel free to open another issue/PR!