Repository navigation
[13.x] Fix Request::route() return type when no route is resolved - #62191
Merged
taylorotwell merged 1 commit intoOct 26, 2026
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for submitting a PR! Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface. Pull requests that are abandoned in draft may be closed due to inactivity. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#55631 narrowed the no-argument return type of
Request::route()from\Illuminate\Routing\Route|object|string|nullto\Illuminate\Routing\Route.The method still returns
nullwhen no route is resolved:getRouteResolver()falls back to a closure returningnull, which is the case for a request that matched no route: a 404 seen by a terminable middleware, a request built in a test or a console context, or a fallback before routing.Static analysers now trust the docblock. Mago (since 1.58) reports
$request->route()?->getName()as a redundant nullsafe operator, and its autofix removes the?->. That turns working code intoCall to a member function getName() on nullat runtime. PHPStan and Psalm users get the same "nullsafe on non-nullable" diagnostics.This PR keeps the conditional type and adds
nullto the no-argument branch:and updates the type test:
No runtime change.
🤖 Generated with Claude Code