This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
You can continue the conversation there. Go to discussion →
Unable to load the "MyCustomFunctions" runtime in "main" at line 1
error message
#4000
Twig version: v3.5.1
PHP version: 7.4
I'm copying this from an answer I just left on stackOverflow:
I was getting:
Unable to load the "MyCustomFunctions" runtime in "main" at line 1
The way I am loading my functions is not inside an extension, but one by one, like so:
$twig->addFunction(new TwigFunction('owner', 'MyCustomFunctions::print'));
This was my function definition as a method of class
MyCustomFunctions
:SOLUTION The problem was that the way I was loading the function was not consistent with the function declaration. I had forgotten to make the function declaration
public static function
, with thatstatic
in there.After adding the static it matches the
::
callable used when loading the function.Obvious, once you see it, but terribly not-obvious from the error message... it took me a long time to figure this one out. The error was only happening at
render
time, not when runningaddFunction
, that didn't make things any easier to diagnose.I suggest improving the error message, if possible. Thanks. I love Twig ❤️
The text was updated successfully, but these errors were encountered: