{"action":"created","issue":{"url":"https://api.github.com/repos/slimphp/Slim/issues/1086","labels_url":"https://api.github.com/repos/slimphp/Slim/issues/1086/labels{/name}","comments_url":"https://api.github.com/repos/slimphp/Slim/issues/1086/comments","events_url":"https://api.github.com/repos/slimphp/Slim/issues/1086/events","html_url":"https://github.com/slimphp/Slim/issues/1086","id":60725886,"number":1086,"title":"Problem with the optional route name?","user":{"login":"akrabat","id":33135,"avatar_url":"https://avatars.githubusercontent.com/u/33135?v=3","gravatar_id":"","url":"https://api.github.com/users/akrabat","html_url":"https://github.com/akrabat","followers_url":"https://api.github.com/users/akrabat/followers","following_url":"https://api.github.com/users/akrabat/following{/other_user}","gists_url":"https://api.github.com/users/akrabat/gists{/gist_id}","starred_url":"https://api.github.com/users/akrabat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akrabat/subscriptions","organizations_url":"https://api.github.com/users/akrabat/orgs","repos_url":"https://api.github.com/users/akrabat/repos","events_url":"https://api.github.com/users/akrabat/events{/privacy}","received_events_url":"https://api.github.com/users/akrabat/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2015-03-11T20:39:29Z","updated_at":"2015-03-11T21:35:33Z","closed_at":null,"body":"Consider:\r\n\r\n```php\r\n$app->get(\r\n    '/',\r\n    function($request, $response) {\r\n        echo \"<p>Hello world</p>\";\r\n    }\r\n);\r\n```\r\nThere's no route name at the end, so `mapRoute()` will assign the last parameter to `$name`. It then works out that there's no callable, so assigns `$name` to `$callable` and then invents a new `$name` string. This works as expected. \r\n\r\nNow consider:\r\n\r\n```php\r\n$app->get(\r\n    '/',\r\n    function($request, $response, $next) {\r\n        echo \"<p>Route middleware functionality</p>\";\r\n        return $next($request, $response);\r\n    },\r\n    function($request, $response) {\r\n        echo \"<p>Hello world</p>\";\r\n    }\r\n);\r\n```\r\n\r\nIn this case, `$name` is the \"Hello world\" closure and `$closure` is the route middleware. This doesn't work. We get this error: *Warning: Illegal offset type in Slim/Slim/Router.php on line 74*.\r\n\r\nIn theory we could detect this by noticing that $name is a callable, but then this case doesn't work:\r\n\r\n```php\r\n$app->get(\r\n    '/',\r\n    function($request, $response, $next) {\r\n        echo \"<p>Route middleware functionality</p>\";\r\n        return $next($request, $response);\r\n    },\r\n    'App\\Controller\\HomeController:home'\r\n);\r\n```\r\n\r\nIn this case, `$name` is now 'App\\Controller\\HomeController:home', & `$callable` is the route middleware closure.\r\n\r\nI *think* the solution is to try and resolve `$name` to a callable using `resolveCallable` and if it turns into a closure, then rearrange stuff.\r\n\r\nClearly, this is why `$name` was a mandatory first parameter earlier in 3's dev cycle and why 2 has a separate `name()` method.\r\n\r\n\r\nThoughts?\r\n"},"comment":{"url":"https://api.github.com/repos/slimphp/Slim/issues/comments/78377463","html_url":"https://github.com/slimphp/Slim/issues/1086#issuecomment-78377463","issue_url":"https://api.github.com/repos/slimphp/Slim/issues/1086","id":78377463,"user":{"login":"silentworks","id":79497,"avatar_url":"https://avatars.githubusercontent.com/u/79497?v=3","gravatar_id":"","url":"https://api.github.com/users/silentworks","html_url":"https://github.com/silentworks","followers_url":"https://api.github.com/users/silentworks/followers","following_url":"https://api.github.com/users/silentworks/following{/other_user}","gists_url":"https://api.github.com/users/silentworks/gists{/gist_id}","starred_url":"https://api.github.com/users/silentworks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/silentworks/subscriptions","organizations_url":"https://api.github.com/users/silentworks/orgs","repos_url":"https://api.github.com/users/silentworks/repos","events_url":"https://api.github.com/users/silentworks/events{/privacy}","received_events_url":"https://api.github.com/users/silentworks/received_events","type":"User","site_admin":false},"created_at":"2015-03-11T21:35:33Z","updated_at":"2015-03-11T21:35:33Z","body":"@akrabat either that or keep it as third parameter, but as @funkatron said, remembering which param comes first isn't very predictable for first time users so creating a method call for each would be better. \r\n\r\nI however wonder if there is a better way internally to do all this before passing over to the mapRoute method, as I don't like the idea of leaking the router implementation out as we did in Slim 2."}}