bramus / router

A lightweight and simple object oriented PHP Router

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unhandled notice exception instead of 404 handling

idashevskii opened this issue · comments

Notice: this issue is applicable for any HTTP method. Lets use PUT for example.
The Router throws 'Undefined index: PUT' PHP notice when there is attempt to call PUT method, and no PUT routers were registered.
Snipet to reproduce:

$router = new \Bramus\Router\Router();
$router->set404(function(){
    echo 'Not found';
});
$router->run();

Expected: 404 handler triggered without PHP notices.
Actual: PHP notice

Already fixed in 968d04f but not yet released

Tested with 968d04f and it still not works.
There is no PHP notice, but 404 handler was not triggered.
Here is my observation

  1. $match argument is unused:
public function trigger404($match = null)
  1. Since 1-arg is unused, no need to pass it. So no needs in isset check, which is root reasoe of the issue.
if (isset($this->afterRoutes[$this->requestedMethod])) {
  $this->trigger404($this->afterRoutes[$this->requestedMethod]);
}

My suggestion is to revert/adjust 968d04f and just to remove transferred but unused argument to trigger404.

I’m open to a PR that would fix this.

commented

Sorry for the question but do you know when the fix will be available?