if ($node->getNode('node') instanceof Twig_Node_Expression_GetAttr) {
$this->changeIgnoreStrictCheck($node->getNode('node'));
}
-
- if (count($node->getNode('arguments'))) {
- throw new Twig_Error_Syntax('The "defined" test only works with simple variables', $this->getLine());
- }
}
public function compile(Twig_Compiler $compiler)
Object methods:
{{ object.foo |default('default') is sameas('default') ? 'ko' : 'ok' }}
{{ object.undefinedMethod |default('default') is sameas('default') ? 'ok' : 'ko' }}
+{{ object.getFoo() |default('default') is sameas('default') ? 'ko' : 'ok' }}
+{{ object.getFoo('a') |default('default') is sameas('default') ? 'ko' : 'ok' }}
+{{ object.undefinedMethod() |default('default') is sameas('default') ? 'ok' : 'ko' }}
+{{ object.undefinedMethod('a') |default('default') is sameas('default') ? 'ok' : 'ko' }}
Deep nested:
{{ nested.undefinedVar.foo.bar |default('default') is sameas('default') ? 'ok' : 'ko' }}
{{ nested.definedArray.0 |default('default') is sameas('default') ? 'ko' : 'ok' }}
Object methods:
ok
ok
+ok
+ok
+ok
+ok
Deep nested:
ok
ok
Object methods:
ok
ok
+ok
+ok
+ok
+ok
Deep nested:
ok
ok
{{ nested['definedArray'][0] is defined ? 'ok' : 'ko' }}
{{ object.foo is defined ? 'ok' : 'ko' }}
{{ object.undefinedMethod is defined ? 'ko' : 'ok' }}
+{{ object.getFoo() is defined ? 'ok' : 'ko' }}
+{{ object.getFoo('a') is defined ? 'ok' : 'ko' }}
+{{ object.undefinedMethod() is defined ? 'ko' : 'ok' }}
+{{ object.undefinedMethod('a') is defined ? 'ko' : 'ok' }}
{{ object.self.foo is defined ? 'ok' : 'ko' }}
{{ object.self.undefinedMethod is defined ? 'ko' : 'ok' }}
{{ object.undefinedMethod.self is defined ? 'ko' : 'ok' }}
ok
ok
ok
+ok
+ok
+ok
+ok
--DATA--
return array(
'definedVar' => 'defined',
ok
ok
ok
+ok
+ok
+ok
+ok