Slim: V4: routes can no longer return null?
I had this route:
$app->get('/', function () {
// nothing
});
It doesn’t seem to work anymore with v4.0.0:
TypeError : Return value of Slim\Handlers\Strategies\RequestResponse::__invoke() must implement interface Psr\Http\Message\ResponseInterface, null returned
Is this something that changed in v4?
I read both the documentation and the upgrade guide and couldn’t find any mention of this.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 26 (23 by maintainers)
An argument for allowing not returning a response from the route might be all the examples out there (from official docs), and the developer’s need to quickly brush up a test route.
Consider these examples from official Slim docs. They do not return a response:
From Slim-Flash:
From Slim 4 itself:
Ultimately, the main argument I see is make the developer’s life easier, which is the whole point behind a framework (at least it was for me when I chose Slim 2.) This error is a distraction.
Can let the framework fall back to a default value when no response is provided. Ensures backward compatibility with Slim 2 and 3.