We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Compile path ignored as soon as I add functions to the compiler

As soon as I add a custom function to my Volt compiler in services.php, for some reason my PHP files stop compiling to my /cache/ directory, and instead compile to the same directory as the volt files. What is the reason for this?

This is the relevant code in my services.php:

$view->registerEngines([
    '.volt' => function ($view) {
        $config = $this->getConfig();

        $volt = new VoltEngine($view, $this);

        // Adding these two lines breaks where my code compiles
        $compiler = $volt->getCompiler();
        $compiler->addFunction('get_object_vars', 'get_object_vars');

        $volt->setOptions([
            'compiledPath' => $config->application->cacheDir,
            'compiledSeparator' => '_'
        ]);

        return $volt;
    }
]);

Move

$compiler = $volt->getCompiler();
$compiler->addFunction('get_object_vars', 'get_object_vars');

after

$volt->setOptions([
  'compiledPath' => $config->application->cacheDir,
  'compiledSeparator' => '_'
]);

Still having this problem, many months later. never found a solution.

xVANKO95's didn't work, as now Phalcon throws the exception Macro 'get_object_vars' does not exist.