Youâve misread my question. I created that typo on purpose to demonstrate a correct error response from Slim.
As opposed to the 500 error I receive for simple PHP syntax errors. Iâm asking if that second error response is correct. I expect to see a PHP error from Slim.
But if the syntax error is within the routes.php file then itâs impossible for PHP to catch this kind of error.
You may use the PHP linter php -l filename.php to check all files for syntax errors.
Slim will catch all Exceptions and âThrowableâ (PHP errors) for you within the route callback.
$app->get('/', function (Request $request, Response $response, array $args) {
// Slim can can handle parser errors here, but not outside the callback
// Message: syntax error, unexpected '='
require 'invalid.php';
return $response;
});
But if you have a parsing error outside the routing callbacks, Slim doesnât handle parsing errors.
This means, everything that PHP can handle is getting handled, but the syntax error must be âwithinâ the âscopeâ of Slim and not âoutsideâ of Slim. Thatâs why this invalid code will not be handled by Slim.
$app->get('/', function (Request $request, Response $response, array $args) {
return $response;
});
// Not "handled" by Slim. You will get a native ParserError.
require 'invalid.php';