Magic function to call functions called from twig templates with a reference to the original variable.
This checks if the array provided by value is containing a reference to the original version. If yes it replaces the argument with its reference.
$name: The name of the function to call.
$arguments: The arguments to process and pass to the called function.
mixed Returns the output of the called function.
public static function __callStatic($name, $arguments) {
foreach ($arguments as $key => $val) {
if (is_object($val) && $val instanceof TwigReference) {
$arguments[$key] =& $val
->getReference();
}
}
// Needed to pass by reference -- could also restrict to maximum one
// argument instead
$args = array();
foreach ($arguments as $key => &$arg) {
$args[$key] =& $arg;
}
return call_user_func_array($name, $args);
}