slimphp / Slim

Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.
http://slimframework.com
MIT License
11.94k stars 1.95k forks source link

Slim in PHP 8.1: site returns error #3143

Closed taylorren closed 2 years ago

taylorren commented 2 years ago

I have been using Slim PHP framework to provide my API service (https://api.rsywx.com).

Recently, I updated my PHP to 8.1 and when I visited the site, it gives the following error:

{
    "statusCode": 500,
    "error": {
        "type": "SERVER_ERROR",
        "description": "ERROR: Return type of App\\Application\\Actions\\ActionPayload::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice on line 67 in file \/home\/tr\/www\/api.rsywx.com\/src\/Application\/Actions\/ActionPayload.php."
    }
}

I have not changed anything in my source code, so I guess the problem raises from Slim framework itself.

Any hints to solve this issue?

odan commented 2 years ago

At first, I thought it could be a bug, but Slim does not do any JSON encoding etc.

I assume this is a PHP 8.1 deprecation in your code:

See this: https://3v4l.org/Fon9f#v8.1.2 vs. this: https://3v4l.org/gqeus#v8.1.2

Please try to add : mixed as return type in file ActionPayload.php on line 67.

l0gicgate commented 2 years ago

This is a Slim-Skeleton issue that's been fixed.

See https://github.com/slimphp/Slim-Skeleton/pull/252