Twig icon indicating copy to clipboard operation
Twig copied to clipboard

PHP Warning: Can't preload unlinked class BinaryOperatorExpressionParser

Open aegladkikh opened this issue 7 months ago • 1 comments

Hi, i have in console output warning, maybe can fix it?

php8.4-fpm-alpine

[09-Jun-2025 07:51:38] NOTICE: PHP message: PHP Warning: Can't preload unlinked class Twig\ExpressionParser\Infix\BinaryOperatorExpressionParser@anonymous: Unknown parent Twig\ExpressionParser\Infix\BinaryOperatorExpressionParser in /app/vendor/twig/twig/src/ExtensionSet.php on line 528

aegladkikh avatar Jun 10 '25 02:06 aegladkikh

As a workaround in a Symfony project with an existing preload.php file, we have manually added the classes first:

/** config/preload.php */
require dirname(__DIR__).'/vendor/autoload.php';

use Symfony\Component\DependencyInjection\Dumper\Preloader;

$containerPreloadFile = dirname(__DIR__).'/var/cache/prod/Infrastructure_UserInterface_ApplicationKernelProdContainer.preload.php';

if (file_exists($containerPreloadFile)) {
    Preloader::preload([
        \Twig\ExpressionParser\ExpressionParserInterface::class,
        \Twig\ExpressionParser\InfixExpressionParserInterface::class,
        \Twig\ExpressionParser\AbstractExpressionParser::class,
        \Twig\ExpressionParser\ExpressionParserDescriptionInterface::class,
        \Twig\ExpressionParser\Infix\BinaryOperatorExpressionParser::class
    ]);

    require $containerPreloadFile;
}

rvoortman avatar Jun 10 '25 13:06 rvoortman