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. |
yoannblot
marked this pull request as ready for review
October 26, 2026 06:19
alies-dev
added a commit
to psalm/psalm-plugin-laravel
that referenced
this pull request
Nov 20, 2026
…l Laravel versions The route resolver returns null when no route matched (error pages, console, queue), and the body is identical on every supported Laravel. Only the PHPDoc changed in 13.39 (laravel/framework#62191), so the non-null Route on 12.x contradicted runtime. Move the nullable return into the common stub and drop the stubs/13.39.0 override. Refs #1926
alies-dev
added a commit
to psalm/psalm-plugin-laravel
that referenced
this pull request
Nov 20, 2026
* fix(stubs): type Request::route() without arguments as nullable on Laravel 13.39+ Laravel 13.39 (laravel/framework#62191) declares the no-arg branch as Route|null; the resolver returns null when no route matched. Override route() in stubs/13.39.0 and keep the non-null branch for older versions. Refs #1926 * fix(stubs): type Request::route() without arguments as nullable on all Laravel versions The route resolver returns null when no route matched (error pages, console, queue), and the body is identical on every supported Laravel. Only the PHPDoc changed in 13.39 (laravel/framework#62191), so the non-null Route on 12.x contradicted runtime. Move the nullable return into the common stub and drop the stubs/13.39.0 override. Refs #1926
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