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 PHP 7.4 #896

Closed
justin-schroeder opened this issue Mar 18, 2020 · 6 comments · Fixed by #899
Closed

Support PHP 7.4 #896

justin-schroeder opened this issue Mar 18, 2020 · 6 comments · Fixed by #899

Comments

@justin-schroeder
Copy link

We’re running into issues getting the stripe SDK to work in PHP 7.4. The error produced is:

Trying to access array offset on value of type int /var/task/vendor/stripe/stripe-php/lib/StripeObject.php:433

This makes sense, because line 433 is using an array accessor in StripeObject::toArray() to determine if a property is public or private before serializing to an array:

if ('_' === $k[0]) ...

However, in PHP 7.4 you should not use array notation to access the first character of a number like in PHP 7.3.

// In PHP 7.3
$x = 123;
echo $x[0]; // outputs NULL

// In PHP 7.4
$x = 123;
echo $x[0]; // throws Notice Trying to access array offset on value of type int in 

For environments that convert error/notices into exceptions (like Laravel) this causes an exception to be thrown.

justin-schroeder added a commit to justin-schroeder/stripe-php that referenced this issue Mar 18, 2020
@ob-stripe
Copy link
Contributor

Thanks for the bug report @justin-schroeder, I was able to reproduce it easily.

Out of curiosity, how did you discover it? Are you using integers as metadata keys?

@justin-schroeder
Copy link
Author

@ob-stripe yep. I suppose we're an odd one out in that sense ha. Sometimes we use numeric keys to "fake" a sortable array of properties.

@ob-stripe
Copy link
Contributor

Just to be sure there's not another issue at play here, this can only happen if you call toArray() after setting metadata with integer keys but before calling save(), right? The API should always return strings for keys, even if integers were passed on the way in.

@justin-schroeder
Copy link
Author

@ob-stripe actually no, the code was a pretty simple controller method (context is Laravel):

    public function getPlans(Request $request)
    {
        $all_plans = \Stripe\Plan::all();
        return response($all_plans);
    }

Some of the plans happen to have metadata with numeric keys.

@ob-stripe
Copy link
Contributor

Just released stripe-php 7.27.3 with your fix, thanks again.

Would you mind sharing your account ID and one of the plan IDs so we can take a closer look at what happens on our end?

@justin-schroeder
Copy link
Author

justin-schroeder commented Mar 18, 2020

Awesome, thanks for the quick fix.

acct_1G1bAyAwqhErLVlI

plan_GqkWIob7obsABb
plan_GqkW2BWGqt1BEZ

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

Successfully merging a pull request may close this issue.

2 participants