You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Calling a closure is not supported in twig right now, any variable passed as \Closure cannot be called directly as Twig looks up the function in global functions (and extensions), the alternative is to call it via __invoke method on closure.
https://3v4l.org/EBR2Y (__invoke method does exist on Closures and work the same way as $closure() works).
Unfortunately this doesn't work in twig as twig_get_attribute uses get_class_methods to determine available methods on an object and fallbacks to __call if it exists and php being php get_class_methods($closure) doesn't return __invokehttps://3v4l.org/VKjAF 🤷♂️ even though it exists and is documented.
I think this can be fixed by checking if $object is instance of \Closure and then allow calling __invoke or is there a better way ?
I am happy to contribute a PR if it makes sense.
The text was updated successfully, but these errors were encountered:
Calling a closure is not supported in twig right now, any variable passed as
\Closure
cannot be called directly as Twig looks up the function in global functions (and extensions), the alternative is to call it via__invoke
method on closure.https://3v4l.org/EBR2Y (
__invoke
method does exist on Closures and work the same way as$closure()
works).Unfortunately this doesn't work in twig as
twig_get_attribute
usesget_class_methods
to determine available methods on an object and fallbacks to__call
if it exists and php being phpget_class_methods($closure)
doesn't return__invoke
https://3v4l.org/VKjAF 🤷♂️ even though it exists and is documented.I think this can be fixed by checking if
$object
is instance of \Closure and then allow calling__invoke
or is there a better way ?I am happy to contribute a PR if it makes sense.
The text was updated successfully, but these errors were encountered: