Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PHP 8.1: silence the deprecation notice about jsonSerialize() return …
…type As of PHP 8.1, PHP adds return type declarations to the PHP native functions. For the `JsonSerializable::jsonSerialize()` interface method, the new signature is: ```php function jsonSerialize(): mixed {} ``` As this libary still supports PHP 5.3, it is not possible to add this return type as: 1. Return types weren't available until PHP 7.0 and 2. the `mixed` return type only became available in PHP 8.0. For libraries supporting PHP 7.0+, it would have been possible to fix this by adding an `array` return type (higher specificity). For libraries still supporting PHP < 7.0, there are two choices: 1. Either decouple from the `JsonSerialize` interface. 2. Or use a PHP 8.1 attribute to silence the deprecation notice. As prior to PHP 8.0, attributes are ignored as if they were comments, it is safe to add the attribute to the library and IMO, this is prefered over decoupling the classes from the `JsonSerializable` interface. To prevent PHPCS tripping up over "something" existing between the function docblock and the declaration, PHPCS 3.6.0 should be used, which is the first PHPCS version with full PHP 8.0 syntax support in the sniffs (albeit that there are still some small things to fix up in PHPCS). Refs: * https://wiki.php.net/rfc/internal_method_return_types * php/php-src#7051
- Loading branch information