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

\TypeError thrown when TwigFunction has an invalid callback. #4393

Open
menno-ll opened this issue Oct 11, 2024 · 0 comments
Open

\TypeError thrown when TwigFunction has an invalid callback. #4393

menno-ll opened this issue Oct 11, 2024 · 0 comments

Comments

@menno-ll
Copy link

We're using WordPress and in there we attempt to load Twig templates.
For us we create a WP_CLI command, which registers itself before WordPress itself is loaded.

Previously (twig version v3.11.1 and before) this all worked great.
Twig allowed functions that were not defined yet to still be compiled as php files.
We did this using the same method as described in #3706.
See our repo of the CLI command.

$twig->registerUndefinedFunctionCallback(function ($name) {
    return new \Twig\TwigFunction($name, $name);
});

But unfortunately now, since version v3.12.0, this does not work anymore and throws the following TypeError.

Uncaught TypeError: Failed to create closure from callable: function "_x" not found or invalid function name in /path/to/project/vendor/twig/twig/src/Util/ReflectionCallable.php:45

Now I have to confess i'm not having a full knowledge of the twig codebase yet.
But after searching and looking at the stacktraces, I've found that somewhere around these PR's to be where the problem started: #4206 or #4207

It seems like even if a function does not exist yet on compilation, it still attempts to extract it's attributes with the new CallableArgumentsExtractor.

Would there be a way to return the functionality to not validate those callable arguments if the function at that stage does not exist, therefore allowing the use of functions that are not yet defined on runtime?

Thanks in advance!

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