web-push-libs / web-push-php

Web Push library for PHP
MIT License
1.69k stars 295 forks source link

An alternative approach for PHP 8.1 support #340

Closed chrisdeeming closed 2 years ago

chrisdeeming commented 2 years ago

@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.

Minishlink commented 2 years ago

@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 :)

chrisdeeming commented 2 years ago

That should be it @Minishlink :)