bug #4728 Fix opcache preload warning for unlinked anonymous class (OndraM)

This PR was merged into the 3.x branch.

Discussion
----------

Fix opcache preload warning for unlinked anonymous class

This fixes PHP opcache preload warning, caused by https://github.com/php/php-src/issues/10131 .  The warning is now produced when the preload is initiated.

> Can't preload unlinked class Twig\ExpressionParser\Infix\BinaryOperatorExpressionParser@anonymous: Unknown parent Twig\ExpressionParser\Infix\BinaryOperatorExpressionParser

This started with Twig 3.21, when the anonymous class started to be used in ExtensionSet.

This is a similar woraround as is already used in a TwigBridge, as suggested by `@nicolas`-grekas here https://github.com/symfony/symfony/pull/38533
Also similar fix is in API platform: https://github.com/api-platform/core/pull/3827

Commits
-------

86997d1bef Fix opcache preload warning for unlinked anonymous class
This commit is contained in:
Fabien Potencier
2026-01-05 21:36:53 +01:00
+4
View File
@@ -27,6 +27,10 @@ use Twig\Node\Expression\AbstractExpression;
use Twig\NodeVisitor\NodeVisitorInterface;
use Twig\TokenParser\TokenParserInterface;
// Help opcache.preload discover always-needed symbols
// @see https://github.com/php/php-src/issues/10131
class_exists(BinaryOperatorExpressionParser::class);
/**
* @author Fabien Potencier <fabien@symfony.com>
*