Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for closures or at least Closure::__invoke #3848

Open
faizanakram99 opened this issue Jun 7, 2023 · 0 comments
Open

Support for closures or at least Closure::__invoke #3848

faizanakram99 opened this issue Jun 7, 2023 · 0 comments

Comments

@faizanakram99
Copy link

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 __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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant