// remove the non-PHP 5.4 version when PHP 5.3 support is dropped
// as the non-optimized version is just a workaround for slow ternary operator
// when the context has a lot of variables
- if (version_compare(phpversion(), '5.4.0RC1', '>=') && ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables())) {
+ if (version_compare(phpversion(), '5.4.0RC1', '>=')) {
// PHP 5.4 ternary operator performance was optimized
$compiler
->raw('(isset($context[')
->string($name)
->raw(']) ? $context[')
- ->string($name)
- ->raw('] : null)')
- ;
+ ->string($name);
+ if ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables()) {
+ $compiler->raw('] : null)');
+ } else {
+ $compiler->raw('] : $this->getContext($context, ')->string($name)->raw('))');
+ }
} else {
$compiler
->raw('$this->getContext($context, ')
$env1 = new Twig_Environment(null, array('strict_variables' => false));
return array(
- array($node, '$this->getContext($context, "foo")', $env),
+ version_compare(PHP_VERSION, '5.4.0') >= 0 ? array($node, '(isset($context["foo"]) ? $context["foo"] : $this->getContext($context, "foo"))', $env) : array($node, '$this->getContext($context, "foo")', $env),
array($node, $this->getVariableGetter('foo'), $env1),
array($self, '$this'),
array($context, '$context'),