Skip to content

Commit 379fb2f

Browse files
committed
Deprecate passing non AbstractExpression nodes to MatchesBinary
1 parent 54d5c00 commit 379fb2f

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# 3.24.0 (2026-XX-XX)
22

3+
* Deprecate passing a non-`AbstractExpression` node to `ParserTwig\Node\Expression\Binary\MatchesBinary` constructor
34
* Deprecate passing a non-`AbstractExpression` node to `Parser::setParent()`
45
* Add support for renaming variables in object destructuring (`{name: userName} = user`)
56
* Add `html_attr_relaxed` escaping strategy that preserves :, @, [, and ] for front-end framework attribute names

doc/deprecated.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ Parser
242242
deprecated as of Twig 3.24; the method will require an ``AbstractExpression``
243243
instance in Twig 4.0.
244244

245+
* Passing non-``AbstractExpression`` nodes to
246+
``Twig\Node\Expression\Binary\MatchesBinary`` constructor is deprecated as of
247+
Twig 3.24; the constructor will require an ``AbstractExpression`` instance in Twig
248+
4.0.
249+
245250
* The ``Twig\Parser::getExpressionParser()`` method is deprecated as of Twig
246251
3.21, use ``Twig\Parser::parseExpression()`` instead.
247252

src/Node/Expression/Binary/MatchesBinary.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Twig\Compiler;
1515
use Twig\Error\SyntaxError;
16+
use Twig\Node\Expression\AbstractExpression;
1617
use Twig\Node\Expression\ConstantExpression;
1718
use Twig\Node\Expression\ReturnBoolInterface;
1819
use Twig\Node\Node;
@@ -21,6 +22,13 @@ class MatchesBinary extends AbstractBinary implements ReturnBoolInterface
2122
{
2223
public function __construct(Node $left, Node $right, int $lineno)
2324
{
25+
if (!$left instanceof AbstractExpression) {
26+
trigger_deprecation('twig/twig', '3.24', 'Passing a "%s" instance to "%s()" first argument is deprecated, pass an "AbstractExpression" instance instead.', $left::class, __METHOD__);
27+
}
28+
if (!$right instanceof AbstractExpression) {
29+
trigger_deprecation('twig/twig', '3.24', 'Passing a "%s" instance to "%s()" second argument is deprecated, pass an "AbstractExpression" instance instead.', $right::class, __METHOD__);
30+
}
31+
2432
if ($right instanceof ConstantExpression) {
2533
$regexp = $right->getAttribute('value');
2634
set_error_handler(static fn ($t, $m) => throw new SyntaxError(\sprintf('Regexp "%s" passed to "matches" is not valid: %s.', $regexp, substr($m, 14)), $lineno));

0 commit comments

Comments
 (0)