stripe-php
stripe-php copied to clipboard
Deprecation warning when using PHP 8.1
There are new rules with the PHP 8.1 update, some fixes must be done in order to prevent errors and warnings. Example below:
I'm current using version v7.112.0.
Are PR's being accepted on this?
Hi @felipeEddy , thank you for the report here. I'd love to get these warnings resolved. How are they surfacing for you? This particular case is only possible if calling the magic __debugInfo()
method on a RequestOptions object (eg. by using var_dump
) which does not have an API key set. I can do an isolated fix for this, but I'd like to make sure these warnings are all resolved and not just this one.
Hey @dcr-stripe, simply loading the bindings in an 8.1 environment will spit out a lot of notices that need to be taken care of. Here are some other examples:
[15-Jun-2022 06:29:06 UTC] PHP Deprecated: Return type of Stripe\StripeObject::offsetGet($k) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /mnt/.../stripe/libs/stripe/lib/StripeObject.php on line 215
[15-Jun-2022 06:29:06 UTC] PHP Deprecated: Return type of Stripe\StripeObject::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /mnt/.../stripe/libs/stripe/lib/StripeObject.php on line 426
OP used a Code Sniffer I believe.
Which version of stripe-php are you using @moonbas3 ?
These warnings today should already be suppressed by #[\ReturnTypeWillChange]
eg. offsetGet, jsonSerialize. These suppressions have been present for a while now.
Locally, if I check my PHP version:
PHP 8.1.5 (cli) (built: Apr 16 2022 00:14:18) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.5, Copyright (c) Zend Technologies
with Zend OPcache v8.1.5, Copyright (c), by Zend Technologies
and pull in stripe-php v8.7.0 (latest), I don't get these deprecation warnings:
<?php
require_once('vendor/autoload.php');
$stripe = new \Stripe\StripeClient('sk_test_123');
I do however get them for other PHP interactions outside of Stripe (eg. with composer, symfony, etc.). So I'm wondering if there's a misconfiguration somewhere 🤔
There is https://github.com/stripe/stripe-php/pull/1273 which should fix the ones coming from Stripe\StripeObject
.
@dcr-stripe Some are caused by PHP Deprecated and others are caused by User Deprecated (e.g., Symfony).
@franmomu Nice! Any chance PHPDoc blocks for the below functions can be included in your PR?
count()
in Stripe\Util\CaseInsensitiveArray
offsetGet()
in Stripe\Collection
offsetGet()
in Stripe\SearchResult
👍 yeah sure, it's done.
Has this issue been resolved because I just pulled v9.5 and still get the errors when running php 8.0:
[08-Sep-2022 18:47:02 America/Chicago] PHP Deprecated: Return type of Stripe\Util\CaseInsensitiveArray::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home3/degiveco/public_html/rv/includes/stripe/vendor/stripe/stripe-php/lib/Util/CaseInsensitiveArray.php on line 44 [08-Sep-2022 18:47:02 America/Chicago] PHP Deprecated: Return type of Stripe\Util\CaseInsensitiveArray::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home3/degiveco/public_html/rv/includes/stripe/vendor/stripe/stripe-php/lib/Util/CaseInsensitiveArray.php on line 57 [08-Sep-2022 18:47:02 America/Chicago] PHP Deprecated: Return type of Stripe\Util\CaseInsensitiveArray::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home3/degiveco/public_html/rv/includes/stripe/vendor/stripe/stripe-php/lib/Util/CaseInsensitiveArray.php on line 34 [08-Sep-2022 18:47:02 America/Chicago] PHP Deprecated: Return type of Stripe\Util\CaseInsensitiveArray::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home3/degiveco/public_html/rv/includes/stripe/vendor/stripe/stripe-php/lib/Util/CaseInsensitiveArray.php on line 51 [08-Sep-2022 18:47:02 America/Chicago] PHP Deprecated: Return type of Stripe\Util\CaseInsensitiveArray::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home3/degiveco/public_html/rv/includes/stripe/vendor/stripe/stripe-php/lib/Util/CaseInsensitiveArray.php on line 24 [08-Sep-2022 18:47:02 America/Chicago] PHP Deprecated: Return type of Stripe\Util\CaseInsensitiveArray::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home3/degiveco/public_html/rv/includes/stripe/vendor/stripe/stripe-php/lib/Util/CaseInsensitiveArray.php on line 29 [08-Sep-2022 18:47:03 America/Chicago] PHP Deprecated: Return type of Stripe\StripeObject::offsetExists($k) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home3/degiveco/public_html/rv/includes/stripe/vendor/stripe/stripe-php/lib/StripeObject.php on line 202 [08-Sep-2022 18:47:03 America/Chicago] PHP Deprecated: Return type of Stripe\StripeObject::offsetGet($k) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home3/degiveco/public_html/rv/includes/stripe/vendor/stripe/stripe-php/lib/StripeObject.php on line 212 [08-Sep-2022 18:47:03 America/Chicago] PHP Deprecated: Return type of Stripe\StripeObject::offsetSet($k, $v) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home3/degiveco/public_html/rv/includes/stripe/vendor/stripe/stripe-php/lib/StripeObject.php on line 197 [08-Sep-2022 18:47:03 America/Chicago] PHP Deprecated: Return type of Stripe\StripeObject::offsetUnset($k) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home3/degiveco/public_html/rv/includes/stripe/vendor/stripe/stripe-php/lib/StripeObject.php on line 207 [08-Sep-2022 18:47:03 America/Chicago] PHP Deprecated: Return type of Stripe\StripeObject::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home3/degiveco/public_html/rv/includes/stripe/vendor/stripe/stripe-php/lib/StripeObject.php on line 218 [08-Sep-2022 18:47:03 America/Chicago] PHP Deprecated: Return type of Stripe\StripeObject::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home3/degiveco/public_html/rv/includes/stripe/vendor/stripe/stripe-php/lib/StripeObject.php on line 422 [08-Sep-2022 18:47:03 America/Chicago] PHP Deprecated: Return type of Stripe\Collection::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home3/degiveco/public_html/rv/includes/stripe/vendor/stripe/stripe-php/lib/Collection.php on line 119 [08-Sep-2022 18:47:03 America/Chicago] PHP Deprecated: Return type of Stripe\Util\Set::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home3/degiveco/public_html/rv/includes/stripe/vendor/stripe/stripe-php/lib/Util/Set.php on line 40
$ composer require stripe/stripe-php Using version ^9.6 for stripe/stripe-php
Deprecated: Return type of Stripe\StripeObject::offsetExists($k) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/project/composer/vendor/stripe/stripe-php/lib/StripeObject.php on line 202
Deprecated: Return type of Stripe\StripeObject::offsetGet($k) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/project/composer/vendor/stripe/stripe-php/lib/StripeObject.php on line 212
Deprecated: Return type of Stripe\StripeObject::offsetSet($k, $v) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/project/composer/vendor/stripe/stripe-php/lib/StripeObject.php on line 197
Deprecated: Return type of Stripe\StripeObject::offsetUnset($k) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/project/composer/vendor/stripe/stripe-php/lib/StripeObject.php on line 207
Deprecated: Return type of Stripe\StripeObject::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/project/composer/vendor/stripe/stripe-php/lib/StripeObject.php on line 218
Deprecated: Return type of Stripe\StripeObject::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/project/composer/vendor/stripe/stripe-php/lib/StripeObject.php on line 424
Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /var/www/html/project/composer/vendor/stripe/stripe-php/lib/Util/RequestOptions.php on line 159
Deprecated: Return type of Stripe\Util\Set::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/project/composer/vendor/stripe/stripe-php/lib/Util/Set.php on line 40
Deprecated: Return type of Stripe\Util\CaseInsensitiveArray::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/project/composer/vendor/stripe/stripe-php/lib/Util/CaseInsensitiveArray.php on line 44
Deprecated: Return type of Stripe\Util\CaseInsensitiveArray::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/project/composer/vendor/stripe/stripe-php/lib/Util/CaseInsensitiveArray.php on line 57
Deprecated: Return type of Stripe\Util\CaseInsensitiveArray::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/project/composer/vendor/stripe/stripe-php/lib/Util/CaseInsensitiveArray.php on line 34
Deprecated: Return type of Stripe\Util\CaseInsensitiveArray::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/project/composer/vendor/stripe/stripe-php/lib/Util/CaseInsensitiveArray.php on line 51
Deprecated: Return type of Stripe\Util\CaseInsensitiveArray::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/project/composer/vendor/stripe/stripe-php/lib/Util/CaseInsensitiveArray.php on line 24
Deprecated: Return type of Stripe\Util\CaseInsensitiveArray::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/project/composer/vendor/stripe/stripe-php/lib/Util/CaseInsensitiveArray.php on line 29
Deprecated: Return type of Stripe\Collection::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/project/composer/vendor/stripe/stripe-php/lib/Collection.php on line 119
same issue using php 8.1
Any plans on fixing this?
Hello, thank you for writing in @degive and @adamz01h.
I am unable to reproduce the deprecation warnings myself on recent versions of stripe-php
and my simple example project. Taking a look at the text you have pasted:
Deprecated: Return type of Stripe\StripeObject::offsetExists($k) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/project/composer/vendor/stripe/stripe-php/lib/StripeObject.php on line 202
This seems to indicate that the offsetExists
function is on line 202 of StripeObject.php
. However, that hasn't been the case since this PR was merged and released in stripe-php v7.104.0, so perhaps somehow in your environment an old version of stripe-php
is being loaded instead?
Can you double-check the version of stripe-php
? If composer is misbehaving, perhaps looking at vendor/stripe/stripe-php/VERSION
is a more robust way to check the version than looking at the composer.json
.
I'm closing, as I suspect this is an environmental issue.
Please do re-open if you can demonstrate deprecation warnings in the latest version - ideally with a sample project and reproduction steps!
I downloaded the latest version and it seems to work fine. Thank you!