Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for PHP 8 #334

Closed
k0ality opened this issue Sep 11, 2023 · 3 comments
Closed

Support for PHP 8 #334

k0ality opened this issue Sep 11, 2023 · 3 comments

Comments

@k0ality
Copy link

k0ality commented Sep 11, 2023

General information

  • SDK/Library version: 6.13.0
  • Environment: Production
  • Language, language version, and OS: PHP 8.0.24, Ubuntu 22.04.1 LTS

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
Copy link
Contributor

👋 @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
Copy link

Neolodor commented Oct 9, 2023

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
Copy link
Contributor

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.

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

No branches or pull requests

3 participants