$compiler
->raw('), ')
- ->repr($this->getAttribute('type'))
- ->raw(')');
+ ->repr($this->getAttribute('type'));
+
+ if ($this->hasAttribute('is_defined_test')) {
+ $compiler->raw(', true');
+ }
+
+ $compiler->raw(')');
}
}
// defined is a special case
if ('defined' === $this->getAttribute('name')) {
- if (!$this->getNode('node') instanceof Twig_Node_Expression_Name){
+ if ($this->getNode('node') instanceof Twig_Node_Expression_Name) {
+ $compiler
+ ->raw($testMap[$this->getAttribute('name')]->compile().'(')
+ ->repr($this->getNode('node')->getAttribute('name'))
+ ->raw(', $context)')
+ ;
+ } elseif ($this->getNode('node') instanceof Twig_Node_Expression_GetAttr) {
+ $this->getNode('node')->setAttribute('is_defined_test', true);
+ $compiler->subcompile($this->getNode('node'));
+ } else {
throw new Twig_Error_Syntax('The "defined" test only works with simple variables', $this->getLine());
}
-
- $compiler
- ->raw($testMap[$this->getAttribute('name')]->compile().'(')
- ->repr($this->getNode('node')->getAttribute('name'))
- ->raw(', $context)')
- ;
-
return;
}
return $context[$item];
}
- protected function getAttribute($object, $item, array $arguments = array(), $type = Twig_Node_Expression_GetAttr::TYPE_ANY)
+ protected function getAttribute($object, $item, array $arguments = array(), $type = Twig_Node_Expression_GetAttr::TYPE_ANY, $noStrictCheck = false)
{
// array
if (Twig_Node_Expression_GetAttr::TYPE_METHOD !== $type) {
}
if (Twig_Node_Expression_GetAttr::TYPE_ARRAY === $type) {
- if (!$this->env->isStrictVariables()) {
+ if (!$this->env->isStrictVariables() || $noStrictCheck) {
return null;
}
}
if (!is_object($object)) {
- if (!$this->env->isStrictVariables()) {
+ if (!$this->env->isStrictVariables() || $noStrictCheck) {
return null;
}
-
throw new Twig_Error_Runtime(sprintf('Item "%s" for "%s" does not exist.', $item, $object));
}
} elseif (isset(self::$cache[$class]['methods']['__call'])) {
$method = $item;
} else {
- if (!$this->env->isStrictVariables()) {
+ if (!$this->env->isStrictVariables() || $noStrictCheck) {
return null;
}