UserFrosting icon indicating copy to clipboard operation
UserFrosting copied to clipboard

ReturnTypeWillChange warning with PHP 8.1

Open lcharette opened this issue 2 years ago • 1 comments

tl;dr : UserFrosting 4.6 doesn't support PHP 8.1, use PHP 8.0.


The following exception can be seen when running UserFrosting 4.6 with PHP 8.1, either in the console or browser.

Deprecated: Return type of Slim\Collection::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in ~/userfrosting/UserFrosting4/app/vendor/slim/slim/Slim/Collection.php on line 112

This is caused by PHP 8.1 new return type. See : https://stackoverflow.com/questions/71133749/reference-return-type-of-should-either-be-compatible-with-or-the-re/71133750#71133750

While UserFrosting code is generally compatible with PHP 8.1, this warning originate in Slim 3, a dependency of UserFrosting. Unfortunately, Slim decided not to fix this issue in v3. See this comment : https://github.com/slimphp/Slim/pull/3186#issuecomment-1098254226

Switching Slim 3 for Slim 4 is not an easy task. It's already been done for the upcoming UserFrosting 5, but a release of V5 is unfortunately not schedule soon, as more work is require around it.

For the time being, UserFrosting 4.6 does not officially support PHP 8.1. You are encouraged to user PHP 8.0 while UF5 is being finalized.

lcharette avatar Apr 23 '22 18:04 lcharette

As for why UF4 uses Slim/Collection, here's the stack trace:

https://github.com/userfrosting/UserFrosting/blob/cc80d4113ba8788b1c1279702b31c82b6a95398a/app/sprinkles/core/src/Core.php#L81

https://github.com/userfrosting/UserFrosting/blob/cc80d4113ba8788b1c1279702b31c82b6a95398a/app/sprinkles/core/src/ServicesProvider/ServicesProvider.php#L252

https://github.com/slimphp/Slim/blob/ce3cb65a06325fc9fe3d0223f2ae23113a767304/Slim/DefaultServicesProvider.php#L54

https://github.com/slimphp/Slim/blob/ce3cb65a06325fc9fe3d0223f2ae23113a767304/Slim/DefaultServicesProvider.php#L41

https://github.com/slimphp/Slim/blob/ce3cb65a06325fc9fe3d0223f2ae23113a767304/Slim/Http/Environment.php#L18

So without a Slim3 fix, our only solution to fix this is to create and register our own \Slim\Http\Environment

lcharette avatar Apr 23 '22 18:04 lcharette

Is there a plan to have UF 5.0 ready before PHP 8.0 exists security updates on Nov 26, 2023? If not, I believe this should be re-evaluated to allow UserFrosting to continue functioning without a high security risk.

fembuelita avatar Jan 28 '23 23:01 fembuelita

Since Slim never updated their code, there's not much we can do for UF4. As for UF 5, it's a slow process since I'm the only one "working on it". It's not far off, but there's a little bit left to do, and the whole doc to write. The best way to help is to test out the latest Alpha and eventually contribute on the missing features/bug fix.

lcharette avatar Feb 03 '23 01:02 lcharette

Understood, @lcharette. Thanks for the update. I am fairly overbooked for a while but as my projects complete I shall endeavor to support you here for our shared interest. Realistically, that's May but I'll set a calendar reminder to follow-up with you.

fembuelita avatar Feb 07 '23 02:02 fembuelita

UF5 is now released and should be used with PHP 8.1

lcharette avatar Nov 25 '23 02:11 lcharette