Undefined array key warning
vassbg opened this issue · comments
First of all, I love that router - it's really great!
I ran into a strange problem today:
I have a few routes defined like so:
$router->post('/users', 'UserController@search');
$router->post('/user', 'UserController@get_by_id');
$router->set404(function() {
header('HTTP/1.1 404 Not Found');
header('Content-Type: application/json');
echo json_encode([
'status' => 404,
'message' => 'Route not found'
]);
});
$router->run();
That works perfectly unless I make a request to a route with a method different than post, like get or put. In that case, before the 404 function output I get a warning: "Undefined array key "PUT" in /.../api/vendor/bramus/router/src/Bramus/Router/Router.php on line 292
If I create a route like so:
$router->get( '/', function() {
header('HTTP/1.1 404 Not Found');
header('Content-Type: application/json');
echo json_encode([
'status' => 404,
'message' => 'Route not found'
]);
});
... the warning for GET is gone, but I don't want to define a route for every method.
Thanks!
This has been fixed about one year ago but not released yet. I don't think it will ever be released.
You can probably use the files directly from master.