Crell / ApiProblem

A simple implementation of the api-problem specification. Includes PSR-15 support.
MIT License
239 stars 21 forks source link

PHP 8.1 compatibility issues #38

Closed bramslob closed 2 years ago

bramslob commented 2 years ago

When upgrading an app to PHP 8.1, while using version 3.5.1, we see the following issues:

Deprecated: Return type of Crell\ApiProblem\ApiProblem::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 [directory]/vendor/crell/api-problem/src/ApiProblem.php on line 599

Deprecated: Return type of & Crell\ApiProblem\ApiProblem::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 [directory]/vendor/crell/api-problem/src/ApiProblem.php on line 607

Deprecated: Return type of Crell\ApiProblem\ApiProblem::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 [directory]/vendor/crell/api-problem/src/ApiProblem.php on line 615

Deprecated: Return type of Crell\ApiProblem\ApiProblem::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 [directory]vendor/crell/api-problem/src/ApiProblem.php on line 623

Deprecated: Return type of Crell\ApiProblem\ApiProblem::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in [directory]/vendor/crell/api-problem/src/ApiProblem.php on line 520

Since some of the signatures will now include the mixed argument & return type (like offsetGet($offset) -> offsetGet(mixed $offset): mixed), this will mean dropping PHP 7.*

Maybe a new major version could be created to accommodate this?

Crell commented 2 years ago

PHP 8.1 includes a new attribute to side-step those warnings when needed. (They're deprecations only; if they're blocking your system, then you have your phpunit settings set too strict.) I took the opportunity to do some other type cleanup as well, and add PHPStan. The 3.6 release is all-green on PHP 8.1.

Cheers.