Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tsaiyihua's avatar

Route Parameters setting problem

Hi, I had a problem about the route parameters in Lumen.

My code is

$app->get('/a/{p1}/b/{p2}', function ($p3, $p2) use ($app) {
    return [$p3, $p2];
});

when I request it by curl -XGET http://localhost:8000/a/1/b/2

It print ["2","1"] not my expect result ["1","2"]

but the code rewrite to

$app->get('/a/{p1}/b/{p2}', function ($p1, $p2) use ($app) {
    return [$p1, $p2];
});

It print ["1","2"], that's my expect result.

I don't know why. Is there any reason for this?

0 likes
2 replies
agCepeda's avatar

The injection of parameters is upon the names of it, you have to put the same name of parameter on the function and the string of route.

tsaiyihua's avatar

Thanks @agCepeda

But I think it should throw the error when the name of parameter on the function or controller function is different to route setting.

In my real case

route setting is /company/{company_id}/search/{keyword}

controller function parameter is function($companyId, $keyword)

the $keyword turn into {company_id}, it trapped me all day :(

Please or to participate in this conversation.