@Minishlink I am so sorry seeing as you already (very efficiently!) merged my previous PR.
There is an alternative approach. I'm not exaggerating when I say I've spent the last 24 hours engrossed in various vendor libraries looking at this kind of stuff with a view to supporting all PHP versions from 7.0 to 8.1 in our application and it's starting to affect my ability to make correct decisions!
PHP 8.1 adds a return type of mixed to the JsonSerializable::jsonSerialize method. While the #[\ReturnTypeWillChange] attribute will work, an alternative is to simply add the array return type.
This will work on all PHP versions you support and still work on PHP 8.1 because array is a more specific type than mixed (which is a union type that consists of many types, including array).
So, nothing wrong with the previous approach but this may be preferred. No issue if you decide to close this in favour of sticking with the original approach.
@chrisdeeming Oh right, yes let's merge this if it's more specific than #[\ReturnTypeWillChange] and it keeps working on PHP < 8.1
There seems to be some conflicts though :)
@Minishlink I am so sorry seeing as you already (very efficiently!) merged my previous PR.
There is an alternative approach. I'm not exaggerating when I say I've spent the last 24 hours engrossed in various vendor libraries looking at this kind of stuff with a view to supporting all PHP versions from 7.0 to 8.1 in our application and it's starting to affect my ability to make correct decisions!
PHP 8.1 adds a return type of
mixed
to theJsonSerializable::jsonSerialize
method. While the#[\ReturnTypeWillChange]
attribute will work, an alternative is to simply add thearray
return type.This will work on all PHP versions you support and still work on PHP 8.1 because
array
is a more specific type thanmixed
(which is a union type that consists of many types, includingarray
).So, nothing wrong with the previous approach but this may be preferred. No issue if you decide to close this in favour of sticking with the original approach.