Skip to content

Undefined array key "GET" in /vendor/bramus/router/src/Bramus/Router/Router.php on line 292 #218

@azbatuk

Description

@azbatuk

Hi,

This seems not a big issue, but I thought I'd report it anyway.

When you make a GET request to a page that does not exist, which should prompt a 404, and there are no defined GET routes, then you get this error message:
"Undefined array key "GET" in /vendor/bramus/router/src/Bramus/Router/Router.php on line 292"

If you define a GET route just as a placeholder. The error disappears.

Same situation is valid for POST requests.

Example:

$router = new \Bramus\Router\Router();

$router->set404(function () {
    header('HTTP/1.1 404 Not Found');
    echo'404: Page not found!';
});

$router->post('/upload', function () {
    // some code
});

$router->run();

Make a GET request (just browse) to any url other than "/upload" to trigger a 404 and I get the error message I mentioned above.

Workaround I am using:

$router->match('GET|POST', '/get-post-route-placeholder', function () {
     // This Route is here so that there is at least one GET and one POST route defined.
     // When there is no GET or no POST routes, a GET or POST request to a non-existing URL that triggers set404() prompts an error:
     // Undefined array key "GET"(or "POST") in /vendor/bramus/router/src/Bramus/Router/Router.php on line 292
});

Did not test any other HTTP methods.

bramus/router is version 1.6.1 installed via composer.

PHP 8.1.2 on Ubuntu 22.04.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions