userfrosting / UserFrosting

Modern PHP user login and management framework
https://www.userfrosting.com
Other
1.64k stars 366 forks source link

ReturnTypeWillChange warning with PHP 8.1 #1206

Closed lcharette closed 1 year ago

lcharette commented 2 years ago

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 commented 2 years ago

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

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

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

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

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

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

fembuelita commented 1 year ago

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.

lcharette commented 1 year ago

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.

fembuelita commented 1 year ago

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.

lcharette commented 1 year ago

UF5 is now released and should be used with PHP 8.1