* 1.14.1 (2013-XX-XX)
+ * made it possible to use named operators as variables
* fixed the possibility to have a variable named 'matches'
* added support for PHP 5.5 DateTimeInterface
break;
case Twig_Token::OPERATOR_TYPE:
- if ('matches' == $token->getValue()) {
+ if (preg_match(Twig_Lexer::REGEX_NAME, $token->getValue(), $matches) && $matches[0] == $token->getValue()) {
+ // in this context, string operators are variable names
$this->parser->getStream()->next();
- $node = new Twig_Node_Expression_Name('matches', $token->getLine());
+ $node = new Twig_Node_Expression_Name($token->getValue(), $token->getLine());
break;
}
--- /dev/null
+--TEST--
+Twig allows to use named operators as variable names
+--TEMPLATE--
+{% for match in matches %}
+ {{- match }}
+{% endfor %}
+{{ in }}
+{{ is }}
+--DATA--
+return array('matches' => array(1, 2, 3), 'in' => 'in', 'is' => 'is')
+--EXPECT--
+1
+2
+3
+in
+is
--- /dev/null
+--TEST--
+Twig does not allow to use two-word named operators as variable names
+--TEMPLATE--
+{{ starts with }}
+--DATA--
+return array()
+--EXCEPTION--
+Twig_Error_Syntax: Unexpected token "operator" of value "starts with" in "index.twig" at line 2
+++ /dev/null
---TEST--
-Twig allows to use 'matches' for a variable name
---TEMPLATE--
-{% for match in matches %}
- {{- match }}
-{% endfor %}
---DATA--
-return array('matches' => array(1, 2, 3))
---EXPECT--
-1
-2
-3