[13.x] Resolve scheduled event callback parameter by type rather than name#60197
Merged
taylorotwell merged 2 commits intoMay 20, 2026
Conversation
shaedrich
reviewed
May 20, 2026
Comment on lines
+794
to
+800
| foreach ($parameters as $name => $type) { | ||
| if ($type !== null && is_a($this, $type)) { | ||
| return [$name => $this]; | ||
| } | ||
| } | ||
|
|
||
| return ['event' => $this]; | ||
| return []; |
This comment was marked as low quality.
This comment was marked as low quality.
Sorry, something went wrong.
Contributor
Author
There was a problem hiding this comment.
array_any returns bool though, so $event would just be true/false — $name from the closure isn't in scope either. Did you mean array_find_key?
Either way I'd lean toward keeping the foreach — the other 3 spots using closureParameterTypes() in this file all do the same $parameters = ...; foreach thing.
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.
Fixes a name-based parameter resolution issue introduced in #60144.
Background
#60144 made it possible to pass the scheduled
Eventinto lifecycle callbacks, and the PR description promises that you can "typehint a callback withEvent $eventas a parameter". However, the implementation only injects the event when the closure parameter is literally named$event. Theis_a($this, $eventParameterType)check in the same method shows the intent was type-based, but the lookup is name-based — these contradict each other.All tests added by #60144 happen to use the parameter name
$event, so the working contract (typehint-based) was never exercised.Reproduction
This throws
BindingResolutionException: the parameter lookup misses on the name'event', no value is injected, and the container falls back to autowiring a newEvent— which fails becauseEventMutexisn't instantiable.Fix
Iterate the closure parameters and inject
$thisinto the first parameter whose type is a class that$thisis an instance of. This matches how Laravel container DI works elsewhere — by type, not by name.After