Im trying to create a twig extension
$loader = new \Twig_Loader_Filesystem(__DIR__.'/../views');
$this->layout = new \Twig_Environment($loader, array(
'cache' => '/../views/cache',
'auto_reload' => true
));
$this->layout->addExtension(new \App\Lib\twig_microtime());
And App\Lib\twig_microtime
class Twig_microtime extends \Twig_Extension {
private $start;
public function getFunctions() {
return array(
'microtime_start' => new \Twig_SimpleFilter($this, 'microtimeStart'),
'microtime_end' => new \Twig_SimpleFilter($this, 'microtimeEnd')
);
}
public function microtimeStart() {
$this->start = microtime(true);
}
public function microtimeEnd() {
return 'eeeee';
}
public function getName() {
return 'microtime_extension';
}
}
So at my layout Im trying to call {{ microtime_end() }} but im getting this error
An exception has been thrown during the compilation of a template ("Argument 2 passed to Twig_NodeVisitor_SafeAnalysis::setSafe() must be of the type array, null given