Closure versus callable type #39251
Unanswered
cyruscollier
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I've noticed some parts of the Laravel codebase require passing in a
Closure
as an argument, either as a strict type or some sort of type check inside that function. In other places however, you are allowed to pass in anycallable
type: Closures, named function strings, invokable objects, or array-style callable.Can someone explain why some parts of the code base are stricter by only allowing Closures? I understand that one can take any callable and convert it into a Closure with
Closure::fromCallable()
, but this seems like an extra step that shouldn't be necessary. Am I missing some subtle difference in scope behavior that requires some functions to only allow the Closure type as a parameter? Thanks in advance for anyone that can offer some insight.Beta Was this translation helpful? Give feedback.
All reactions