- Issue created by @donquixote
- 🇩🇪Germany donquixote
I see this is also done in core.
📌 Delegate all hook invocations to ModuleHandler Fixed
https://git.drupalcode.org/project/drupal/-/commit/7e81e515dacdf07c0c6d0...In one place, invokeAllWith() in core, the reason might be to encapsulate the callable from other code.
In the other place, invoke() in core, the reason is not so clear.I see "Closure::fromCallable" mentioned in #2616814, but I don't see the explanation why we need it.
I also see you were involved :) - 🇩🇪Germany donquixote
Btw the variable
$hookInvoker
in core should rather be something like$implementorCallback
or$implementingCallback
.(sorry to spam this issue with somewhat off-topic remarks)
- Status changed to Closed: works as designed
almost 2 years ago 7:52am 14 June 2023 - 🇦🇺Australia dpi Perth, Australia
To be honest I think the `callable` typehint is misleading. It should have been Closure from the start. That was the intention. I dont know how callable vs Closure slipped by, maybe \Closure as a typehint just feels weird. Regardless.
Btw the variable $hookInvoker in core should rather be something like
The variable makes sense knowing the history (per above). I had intended it to only be a closure. I'm pretty sure its all `$hook` in core though, there are remnants of `$hookInvoker` in Hux
As such I have no plan to change it.
Given the test results from https://wiki.php.net/rfc/closurefromcallable I'm not really concerned about performance, it seems to be better in some cases.
As you may see in Hux particularly, these closures are stored in memory and "cached" just for the request. I imagine there is low overhead in this aspect.
--
I think the best way forward would be to progress with replacing `callable` with `Closure`, I think in reality there will be little trouble changing, as this is a narrowing of the type.