Call to a member function getAttribute() on null

<?php namespace middleware; /** * middleware */ class guestMiddleware { protected $args; public function _constuct($args) { echo $args; } public function __invoke($Request, $Response, $next) { //$foo = $request->getAttribute('email') $route = $request->getAttribute('route'); $routeName = $route->getName(); $groups = $route->getGroups(); $methods = $route->getMethods(); $arguments = $route->getArguments(); print "Route Info: " . print_r($route, true); print "Route Name: " . print_r($routeName, true); print "Route Groups: " . print_r($groups, true); print "Route Methods: " . print_r($methods, true); print "Route Arguments: " . print_r($arguments, true); $id = $request->getAttribute('route')->getArgument('email'); return $next($request, $response); } } ?>

onfig = [‘settings’ => [
‘determineRouteBeforeAppMiddleware’ => true,
‘displayErrorDetails’ => true,
]];
$app = new \Slim\App($config);

// Fetch DI Container
$container = $app->getContainer();
//print_r($container);

//print_r($views);
// Instantiate and add Slim specific extension
/*
$mw = function ($request, $response, $next) {
//$response->write(‘hello’);
$route = $request->getAttribute(‘route’);
$arg = $route->getArguments();
$body = $response->getBody()->write(‘hello’);
$a = $request->getQueryparams();
echo $foo = $request->getAttribute(‘email’);
print_r($foo);

$response = $next($request, $response);
//$response->getBody()->write();
	//$response = $args['email'];
return $response;

};
*/
//$app->group(’/’,function() use($app){

$app->get('/getmail/{email}',function ($request, $response, $args){
//$obj = new ps;

echo $args[‘email’];
$status = $response->getStatusCode();
return $response;

})->add(new middleware\guestMiddleware(“hello”));

/*
->add(function ($request, $response, $next) {
$id = $request->getAttribute(‘route’)->getArgument(‘email’);
return $next($request, $response);
});

//});
*/
$app->run();

Looks like the same issue as your other thread… PHP variables are case sensitive. $Request is different than $request. Try this.

public function __invoke(Request $request, Response $response, $next)

Or if you don’t wish to type hint:

public function __invoke($request, $response, $next)