Function name must be a string exception with middleware


I’m trying out Slim3 for a future project, and can’t explain this exception for me.

The message is ‘Function name must be a string’ and it is caused by an empty middleware:

 $app->add(function ($request, $response, $next) {
     $response = $next($request, $response);
     return $response;

My error handling is:

$container['errorHandler'] = function ($container) {
    return function ($request, $response, $exception) use ($container) {
        file_put_contents("/home/stratoss/test", print_r($exception, true) . ' ');
        return $response;

$container['phpErrorHandler'] = function ($container) {
    return $container['errorHandler'];
$container['notFoundHandler'] = function ($container) {
    return true;

Basically, what I’m trying to achieve with returning true for notFoundHandler is to disable the default 404 layout, and the empty middleware will be a rate limiter for the API.

The PHP version I’m using is 7.0.15

Turns out that returning true is triggering the error. Can’t delete my question.