Skip to content
New issue

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

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

Already on GitHub? # to your account

[11.x] Fix routeCollection get method return value when searching by dot not… #54672

Conversation

abdel-aouby
Copy link
Contributor

Changes

  • Remove the use of Arr::get($this->routes, $method, []) from the get method in \Illuminate\Routing\RouteCollection::get because it allows to return a route object when searching with "dot" notation. despite the method name, parameter, and PHPDoc indicating that the search is performed by $method (e.g GET , POST ...) and should return array of Route objects when found

Changes
as described and discussed in #54541

  • The current implementation of the get method in \Illuminate\Routing\RouteCollection::get has a side effect that allows us to search by "dot" notation
    example: $this->routeCollectionget->('GET.foo/index'); will return an object instance of Route (not array)
    which contradict:
  1. The parameter name ($method)
  2. The phpDoc that says it should return \Illuminate\Routing\Route[] and not \Illuminate\Routing\Route object as it is in this case

Solution

  • Eliminate the side effect by removing the search by "dot" notation that is provided by Arr::get() and use null-coalescing operator instead to perform a search on the routes collection (first level that contains the methods)

@taylorotwell taylorotwell merged commit 98ddaa6 into laravel:11.x Feb 18, 2025
44 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants