Middleware in Slim

Now I read the documentation of Slim. I wanted to create the middleware for example in the doc

$app = new \Slim\App();

$mw = function ($request, $response, $next) {
    $response = $next($request, $response);

    return $response;

$app->get('/', function ($request, $response, $args) {
	$response->getBody()->write(' Hello ');

	return $response;


But when I execute the code I got the error Too few arguments to function Closure::{closure}(), 2 passed in /home/roma/slim/vendor/slim/slim/Slim/MiddlewareDispatcher.php on line 313 and exactly 3 expected in /home/roma/slim/src/public/index.php:121
I don’t understand what is $next ?

Hi @ogurchik Your code shows a Slim 3 example. Which version of Slim are you referring to?

Ohhh, man! You are right. I have version 4. Thank you.