With the following setup:
use Twig\Environment;
use Twig\Loader\ArrayLoader;
$twig = new Environment(
new ArrayLoader([
'test' => '{{ test.test() }}',
]),
);
$twig->enableStrictVariables();
$template = $twig->load('test');
attempting the following will succeed:
$template->render([
'test' => new class {
public function test()
{
return 'test';
}
},
]);
while the following will fail:
$template->render([
'test' => [
'test' => fn() => 'test',
],
]);
I am motivated to try the second one in tests, to avoid having to create complicated objects which might be tricky to do in an isolated way.
I'm curious to know if this is a design decision, or a niche which hasn't been popular enough to implement. I note the existence of two related issues:
but I'm not sure if they cover this case, or distinct ones.
Thank you!
With the following setup:
attempting the following will succeed:
while the following will fail:
I am motivated to try the second one in tests, to avoid having to create complicated objects which might be tricky to do in an isolated way.
I'm curious to know if this is a design decision, or a niche which hasn't been popular enough to implement. I note the existence of two related issues:
Closure::__invoke#3848but I'm not sure if they cover this case, or distinct ones.
Thank you!