sp-api-sdk
sp-api-sdk copied to clipboard
Mark overridden methods from native classes with ReturnTypeWillChange attribute
Initial issue: https://github.com/amazon-php/sp-api-sdk/issues/230
While working with this library on a project using PHP 8.1 we got the next error:
Uncaught yii\base\ErrorException: Return type of AmazonPHP\SellingPartner\Model\ProductTypesDefinitions\ProductTypeList::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/vendor/amazon-php/sp-api-sdk/src/AmazonPHP/SellingPartner/Model/ProductTypesDefinitions/ProductTypeList.php:219
When PHP is configured to strict error reporting it will trigger error exceptions on deprecation notices and this may affect many projects with similar settings that are using this good library.
To avoid such problems, PHP suggests writing #[\ReturnTypeWillChange]
attribute before overridden method names.
It will not affect code for PHP < 8.0, because #
symbol will be parsed as comment in these versions.
Example: official AWS SDK library that supports PHP >= 5.5 and uses this attribute in several classes like this: https://github.com/aws/aws-sdk-php/blob/master/src/Api/AbstractModel.php