Deprecate passing a non-AbstractExpression node to Parser::setParent()

This commit is contained in:
Fabien Potencier
2026-02-22 15:26:09 +01:00
parent 0319c822d1
commit 54d5c004b4
4 changed files with 11 additions and 1 deletions
+1
View File
@@ -1,5 +1,6 @@
# 3.24.0 (2026-XX-XX)
* Deprecate passing a non-`AbstractExpression` node to `Parser::setParent()`
* Add support for renaming variables in object destructuring (`{name: userName} = user`)
* Add `html_attr_relaxed` escaping strategy that preserves :, @, [, and ] for front-end framework attribute names
* Add support for short-circuiting in null-safe operator chains
+4
View File
@@ -238,6 +238,10 @@ Parser
* Passing ``null`` to ``Twig\Parser::setParent()`` is deprecated as of Twig
3.12.
* Passing a non-``AbstractExpression`` node to ``Twig\Parser::setParent()`` is
deprecated as of Twig 3.24; the method will require an ``AbstractExpression``
instance in Twig 4.0.
* The ``Twig\Parser::getExpressionParser()`` method is deprecated as of Twig
3.21, use ``Twig\Parser::parseExpression()`` instead.
+4
View File
@@ -416,6 +416,10 @@ class Parser
trigger_deprecation('twig/twig', '3.12', 'Passing "null" to "%s()" is deprecated.', __METHOD__);
}
if (null !== $parent && !$parent instanceof AbstractExpression) {
trigger_deprecation('twig/twig', '3.24', 'Passing a "%s" instance to "%s()" is deprecated, pass an "AbstractExpression" instance instead.', $parent::class, __METHOD__);
}
if (null !== $this->parent) {
throw new SyntaxError('Multiple extends tags are forbidden.', $parent->getTemplateLine(), $parent->getSourceContext());
}
+2 -1
View File
@@ -26,6 +26,7 @@ use Twig\Error\SyntaxError;
use Twig\Lexer;
use Twig\Loader\ArrayLoader;
use Twig\Node\EmptyNode;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Node;
use Twig\Node\Nodes;
use Twig\Node\SetNode;
@@ -208,7 +209,7 @@ EOF, 'index')));
protected function getParser()
{
$parser = new Parser(new Environment(new ArrayLoader()));
$parser->setParent(new EmptyNode());
$parser->setParent(new ConstantExpression('base.html', 1));
$p = new \ReflectionProperty($parser, 'stream');
$p->setValue($parser, new TokenStream([], new Source('', '')));