Use Template->getContext in non-strict mode too
authornikic <nikita.ppv@googlemail.com>
Sat, 2 Jul 2011 21:43:11 +0000 (23:43 +0200)
committernikic <nikita.ppv@googlemail.com>
Sat, 2 Jul 2011 21:44:47 +0000 (23:44 +0200)
lib/Twig/Node/Expression/Name.php
lib/Twig/Template.php

index f7d1875..fceda2b 100644 (file)
@@ -34,10 +34,8 @@ class Twig_Node_Expression_Name extends Twig_Node_Expression
             }
         } elseif (isset($specialVars[$name])) {
             $compiler->raw($specialVars[$name]);
-        } elseif ($compiler->getEnvironment()->isStrictVariables()) {
-            $compiler->raw(sprintf('$this->getContext($context, \'%s\')', $name));
         } else {
-            $compiler->raw(sprintf('(isset($context[\'%s\']) ? $context[\'%s\'] : null)', $name, $name));
+            $compiler->raw(sprintf('$this->getContext($context, \'%s\')', $name));
         }
     }
 }
index aaef78a..f4ff59e 100644 (file)
@@ -224,11 +224,17 @@ abstract class Twig_Template implements Twig_TemplateInterface
      * @param array   $context The context
      * @param string  $item    The variable to return from the context
      *
-     * @throws Twig_Error_Runtime if the variable does not exist
+     * @return The content of the context variable
+     *
+     * @throws Twig_Error_Runtime if the variable does not exist and Twig is running in strict mode
      */
     protected function getContext($context, $item)
     {
         if (!array_key_exists($item, $context)) {
+            if (!$this->env->isStrictVariables()) {
+                return null;
+            }
+
             throw new Twig_Error_Runtime(sprintf('Variable "%s" does not exist', $item));
         }