Home > Back-end >  After updating from Symfony 5.3 to 6, I got a Kernel error
After updating from Symfony 5.3 to 6, I got a Kernel error

Time:02-15

After updating my composer, I got the following error when upgrading to Symfony 6:

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

It showed the trace on my Kernel.php file on line 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 contents:

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. 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

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.

After running bin/console cache:clear I got the following message:

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.

CodePudding user response:

I found the issue.

After creating a separate new Symfony 6 project, this was the cause of the error:

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.

  • Related