code: public function addFunction($name, $function = null)
      {
          if (!$name instanceof Twig_SimpleFunction && !($function instanceof Twig_SimpleFunction || $function instanceof Twig_FunctionInterface)) {
              throw new LogicException('A function must be an instance of Twig_FunctionInterface or Twig_SimpleFunction.');
          }
  
          if ($name instanceof Twig_SimpleFunction) {
              $function = $name;
              $name = $function->getName();
          } else {
              @trigger_error(sprintf('Passing a name as a first argument to the %s method is deprecated since version 1.21. Pass an instance of "Twig_SimpleFunction" instead when defining function "%s".', __METHOD__, $name), E_USER_DEPRECATED);
          }
  
          if ($this->extensionInitialized) {
              throw new LogicException(sprintf('Unable to add function "%s" as extensions have already been initialized.', $name));
          }
  
          $this->staging->addFunction($name, $function);
      }
docs: Registers a Function.
  
  @param string|Twig_SimpleFunction                 $name     The function name or a Twig_SimpleFunction instance
  @param Twig_FunctionInterface|Twig_SimpleFunction $function