deprecated "if" conditions on "for" tags

This commit is contained in:
Fabien Potencier
2019-05-09 14:09:06 +02:00
parent d891cda943
commit 5d1d90ba53
4 changed files with 9 additions and 0 deletions
+1
View File
@@ -1,5 +1,6 @@
* 2.10.0 (2019-XX-XX)
* deprecated "if" conditions on "for" tags
* added "filter", "map", and "reduce" filters (and support for arrow functions)
* fixed partial output leak when a PHP fatal error occurs
* optimized context access on PHP 7.4
+4
View File
@@ -39,6 +39,10 @@ Tags
* The ``filter`` tag is deprecated in Twig 2.9. Use the ``apply`` tag instead
(the ``Twig\TokenParser\FilterTokenParser`` classes is also deprecated).
* Adding an ``if`` condition on a ``for`` tag is deprecated in Twig 2.10. Use a
``filter`` filter or an "if" condition inside the "for" body instead (if your condition
depends on a variable updated inside the loop)
Final Classes
-------------
+2
View File
@@ -43,6 +43,8 @@ final class ForTokenParser extends AbstractTokenParser
$ifexpr = null;
if ($stream->nextIf(/* Token::NAME_TYPE */ 5, 'if')) {
@trigger_error(sprintf('Using an "if" condition on "for" tag is deprecated since Twig 2.10.0, use a "filter" filter or an "if" condition inside the "for" body instead (if your condition depends on a variable updated inside the loop).', __CLASS__), E_USER_DEPRECATED);
$ifexpr = $this->parser->getExpressionParser()->parseExpression();
}
@@ -1,5 +1,7 @@
--TEST--
"for" tag takes a condition
--DEPRECATION--
Using an "if" condition on "for" tag is deprecated since Twig 2.10.0, use a "filter" filter or an "if" condition inside the "for" body instead (if your condition depends on a variable updated inside the loop).
--TEMPLATE--
{% for i in 1..5 if i is odd -%}
{{ loop.index }}.{{ i }}{{ foo.bar }}