braintree / braintree_php

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

Support for PHP 8 #334

Closed k0ality closed 10 months ago

k0ality commented 1 year ago

General information

Issue description

The package doesn't have a PHP version range locked, only the lower limit (currently composer requires "php": ">=7.3.0"), which is misleading, considering that a major update for SDK (6.0.0) was released on Apr 6, 2021 and PHP 8.0 was already around since 26 Nov 2020. However, the SDK still lacks proper support for PHP 8.0, not to mention 8.1 and 8.2.

Just one of the examples that proves my point:

public function testBraintreeDisputeObject()
    {
        $braintreeDispute = \Braintree\Dispute::factory([
            'id' => 'testDisputeId',
            'transaction' => \Braintree\Transaction::factory([
                'id' => 'testTransactionId',
            ]),
        ]);

        $braintreeDispute->transaction->id;
        //TypeError : array_key_exists(): Argument #2 ($array) must be of type array, Braintree\Transaction given
        //file and line: /Braintree/Instance.php:31

        $braintreeDispute->toArray();
        //TypeError : array_map(): Argument #2 ($array) must be of type array, Braintree\Transaction given
        //file and line: Braintree/Instance.php:114
    }

Dispute object is just an example, the error will haunt any class that extends Instance, of course.

https://www.php.net/manual/en/migration80.incompatible.php

The ability to use array_key_exists() with objects has been removed. isset() or property_exists() may be used instead.

hollabaq86 commented 1 year ago

👋 @k0ality thanks for reaching out. You're correct that we only have limitations on the lowest available version that the library is built to support. This is so that we can add support for newer versions without breaking integrations for users still on older versions.

We addressed some issues with PHP 8.1 in a previous version, and we also run internal CI tests in PHP 8.0-8.2 but we have not received any recent errors indicating a breaking change similar to the comments in your code sample above.

Can you clarify how these errors are surfacing for you so that we can improve how we identify issues like this and ultimately resolve the issue you're encountering?

Neolodor commented 12 months ago

Hi!

Faced same issue on serializing error object to array via toArray method:

array_map(): Argument #2 ($array) must be of type array, null given

As far as I see, this issue actual for all inheritors of Braintree/Base.

hollabaq86 commented 10 months ago

Hey @Neolodor! I think the issue you're seeing is #336 and that may ultimately be the root of this issue, too. Since @k0ality didn't provide any additional details I'm going to close this issue, we can always reopen it if we get more info.