简体   繁体   English

从 Symfony 5.3 更新到 6 后,出现内核错误

[英]After updating from Symfony 5.3 to 6, I got a Kernel error

After updating my composer, I got the following error when upgrading to Symfony 6:更新作曲家后,升级到 Symfony 6 时出现以下错误:

Typed property Symfony\Component\Routing\Annotation\Route::$env must not be accessed before initialization类型化属性 Symfony\Component\Routing\Annotation\Route::$env 在初始化之前不能被访问

It showed the trace on my Kernel.php file on line 30:它在我的Kernel.php文件的第 30 行显示了跟踪:

<?php

namespace App;

use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

class Kernel extends BaseKernel
{
    use MicroKernelTrait;

    protected function configureContainer(ContainerConfigurator $container): void
    {
        $container->import('../config/{packages}/*.yaml');
        $container->import('../config/{packages}/'.$this->environment.'/*.yaml');

        if (is_file(\dirname(__DIR__).'/config/services.yaml')) {
            $container->import('../config/services.yaml');
            $container->import('../config/{services}_'.$this->environment.'.yaml');
        } elseif (is_file($path = \dirname(__DIR__).'/config/services.php')) {
            (require $path)($container->withPath($path), $this);
        }
    }

    protected function configureRoutes(RoutingConfigurator $routes): void
    {
        $routes->import('../config/{routes}/'.$this->environment.'/*.yaml');
        $routes->import('../config/{routes}/*.yaml'); //<--- Error pointing here 

        if (is_file(\dirname(__DIR__).'/config/routes.yaml')) {
            $routes->import('../config/routes.yaml');
        } elseif (is_file($path = \dirname(__DIR__).'/config/routes.php')) {
            (require $path)($routes->withPath($path), $this);
        }
    }
}

I suspect this actually has nothing to do with my Kernel file, but my routing.yaml file?我怀疑这实际上与我的内核文件无关,但我的routing.yaml文件?

routing.yaml contents: routing.yaml内容:

framework:
    router:
        utf8: true
            # Configure how to generate URLs in non-HTTP contexts, such as CLI commands.
            # See https://symfony.com/doc/current/routing.html#generating-urls-in-commands
            #default_uri: http://localhost

I updated all of my packages utilizing composer recipes:update .我使用composer recipes:update了我的所有软件包。 After running that command, I'm now back to the original error:运行该命令后,我现在回到原来的错误:

Typed property Symfony\Component\Routing\Annotation\Route::$env must not be accessed before initialization类型化属性 Symfony\Component\Routing\Annotation\Route::$env 在初始化之前不能被访问

I compared the file with the original here: https://github.com/symfony/symfony/blob/6.0/src/Symfony/Component/Routing/Annotation/Route.php and it's exactly the same.我在这里将文件与原始文件进行了比较: https ://github.com/symfony/symfony/blob/6.0/src/Symfony/Component/Routing/Annotation/Route.php,它完全一样。

After running bin/console cache:clear I got the following message:运行bin/console cache:clear后,我收到以下消息:

00:00:27 WARNING   [app] Failed to generate ConfigBuilder for extension Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ { …},"extensionClass" => "Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension"]
00:00:27 WARNING   [app] Failed to generate ConfigBuilder for extension Sensio\Bundle\FrameworkExtraBundle\DependencyInjection\SensioFrameworkExtraExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ { …},"extensionClass" => "Sensio\Bundle\FrameworkExtraBundle\DependencyInjection\SensioFrameworkExtraExtension"]
00:00:27 WARNING   [app] Failed to generate ConfigBuilder for extension Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ { …},"extensionClass" => "Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension"]
00:00:27 WARNING   [app] Failed to generate ConfigBuilder for extension Symfony\Bundle\WebProfilerBundle\DependencyInjection\WebProfilerExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ { …},"extensionClass" => "Symfony\Bundle\WebProfilerBundle\DependencyInjection\WebProfilerExtension"]
00:00:27 WARNING   [app] Failed to generate ConfigBuilder for extension Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ { …},"extensionClass" => "Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension"]
00:00:27 WARNING   [app] Failed to generate ConfigBuilder for extension Symfony\Bundle\DebugBundle\DependencyInjection\DebugExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ { …},"extensionClass" => "Symfony\Bundle\DebugBundle\DependencyInjection\DebugExtension"]
00:00:27 WARNING   [app] Failed to generate ConfigBuilder for extension Symfony\Bundle\MakerBundle\DependencyInjection\MakerExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ { …},"extensionClass" => "Symfony\Bundle\MakerBundle\DependencyInjection\MakerExtension"]
00:00:27 WARNING   [app] Failed to generate ConfigBuilder for extension Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ { …},"extensionClass" => "Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension"]
00:00:27 WARNING   [app] Failed to generate ConfigBuilder for extension Doctrine\Bundle\MigrationsBundle\DependencyInjection\DoctrineMigrationsExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ { …},"extensionClass" => "Doctrine\Bundle\MigrationsBundle\DependencyInjection\DoctrineMigrationsExtension"]
00:00:27 WARNING   [app] Failed to generate ConfigBuilder for extension Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ { …},"extensionClass" => "Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension"]
00:00:27 WARNING   [app] Failed to generate ConfigBuilder for extension Twig\Extra\TwigExtraBundle\DependencyInjection\TwigExtraExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ { …},"extensionClass" => "Twig\Extra\TwigExtraBundle\DependencyInjection\TwigExtraExtension"]
00:00:27 WARNING   [app] Failed to generate ConfigBuilder for extension Symfony\WebpackEncoreBundle\DependencyInjection\WebpackEncoreExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ { …},"extensionClass" => "Symfony\WebpackEncoreBundle\DependencyInjection\WebpackEncoreExtension"]
00:00:27 WARNING   [app] Failed to generate ConfigBuilder for extension SymfonyCasts\Bundle\VerifyEmail\DependencyInjection\SymfonyCastsVerifyEmailExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ { …},"extensionClass" => "SymfonyCasts\Bundle\VerifyEmail\DependencyInjection\SymfonyCastsVerifyEmailExtension"]
00:00:27 WARNING   [app] Failed to generate ConfigBuilder for extension Doctrine\Bundle\FixturesBundle\DependencyInjection\DoctrineFixturesExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ { …},"extensionClass" => "Doctrine\Bundle\FixturesBundle\DependencyInjection\DoctrineFixturesExtension"]
00:00:27 WARNING   [app] Failed to generate ConfigBuilder for extension SymfonyCasts\Bundle\ResetPassword\DependencyInjection\SymfonyCastsResetPasswordExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ { …},"extensionClass" => "SymfonyCasts\Bundle\ResetPassword\DependencyInjection\SymfonyCastsResetPasswordExtension"]
00:00:27 CRITICAL  [php] Uncaught Error: Typed property Symfony\Component\Routing\Annotation\Route::$env must not be accessed before initialization ["exception" => Error { …}]

The only place I see that has the $env variable is within bin/.phpunit/phpunit-8.5-0/** in 4 files within that directory.我看到的唯一有$env变量的地方是bin/.phpunit/phpunit-8.5-0/**在该目录中的 4 个文件中。

I found the issue.我发现了这个问题。

After creating a separate new Symfony 6 project, this was the cause of the error:在创建一个单独的新 Symfony 6 项目后,这是错误的原因:

framework.yaml

session:
        # enabled: true
        handler_id: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler

to

session:
        # enabled: true
        handler_id: null

That fixed the issue.这解决了这个问题。

In case it helps anyone, I had a similar issue after upgrading from symfony 5 to 6.如果它对任何人有帮助,我在从 symfony 5 升级到 6 后遇到了类似的问题。

Typed property Symfony\Component\Routing\Annotation\Route::$name must not be accessed before initialization

Clearing the cache resolved this issue for me:清除缓存为我解决了这个问题:

php bin/console cache:clear
# or if running php unit tests fails
php bin/console cache:clear --env=test

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM