Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
azbatuk opened this issue Feb 17, 2024 · 1 comment

Comments

@azbatuk
Copy link

azbatuk commented Feb 17, 2024

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.

@joepdooper
Copy link

joepdooper commented Mar 1, 2024

Hi @bramus

I have the same issue as @azbatuk.

Lets say I have following inside a php hook:

$router = new \Bramus\Router\Router();
$router->setBasePath(_SUBFOLDER);
$router->post('/text/(\w+)/(\d+)(/\w+)?(/\d+)?', function($action, $id, $template_route = null, $template_id = null) {

});
$router->run();

…then I get the same error:

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

It is just a test, the idea is that the $router will be set before the hook and the $router will run just after the hook so multiple $routes can be set in the hook.

bramus/router version 1.6 installed via composer.

PHP 8.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants