-
Notifications
You must be signed in to change notification settings - Fork 114
PHP 8.1 Compatibility #69
Description
PHP 8.1 introduced return type declarations for most internal methods. Several classes in this library implement various built-in interfaces such as Iterator and ArrayAccess. These classes currently cause deprecation warnings since they don't provide the proper return type hints.
There are two ways to approach this problem.
Approach 1: Add #[ReturnTypeWillChange] Attribute
PHP 8.1 introduces the #[ReturnTypeWillChange] attribute which can be used to temporarily suppress the deprecation notice until PHP 9. Since the attribute syntax is backwards compatible (older versions will treat it as a code comment), this would not break backwards compatibility. It is, however, not a real solution as it simply hides the issue.
Approach 2: Adding the missing type hints
The "correct" solution would be to add the missing type hints to the various interface methods. This would of course be a breaking change as return types are only supported since PHP 7.0.
That being said, this project currently supports PHP versions all the way down to PHP 5.6, which as been EOL for close to 3 years. I think it's reasonable to tag a new version which fixes the deprecation notices in PHP 8.1 and drops support for all PHP versions that don't receive security fixes anymore (< PHP 7.4).
I'd be happy to provide the necessary pull requests.