Group Middleware error

Using the Group Middleware example from http://www.slimframework.com/docs/v4/concepts/middleware.html throws this error:

Fatal error : Uncaught TypeError: Return value of Slim\Handlers\Strategies\RequestResponse::__invoke() must implement interface Psr\Http\Message\ResponseInterface, int returned

What is the fix to this error?

Only this code could cause the error you mentioned:

return $response->getBody()->write('data');

Edit:

I didn’t find it in the documentation. Where exactly did you find it?

I found it here.

$app->get('/', function (Request $request, Response $response) {
    return $response->getBody()->write('Hello World');
});

Replace it with this code:

$app->get('/', function (Request $request, Response $response) {
    $response->getBody()->write('Hello World');
    return $response;
});

This page will be fixed soon: https://github.com/slimphp/Slim-Website/pull/497

Thanks for the fix Odan.