Skip to content

[3.4] Cannot redeclare class Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser #25334

Closed
@gnutix

Description

@gnutix
Contributor
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 3.4.*
PHP version 5.6.25

Stacktrace

We're currently upgrading a Symfony project to 3.4 on PHP 5.6.25 and my colleague has been having this issue since I've added the following block of code to our AppKernel::registerContainerConfiguration method:

        $loader->load(function (ContainerBuilder $container) {
            $container->setParameter('container.autowiring.strict_mode', true);
            $container->setParameter('container.dumper.inline_class_loader', true);
            $container->addObjectResource($this);
        });

It only happened on a second request, and often it had to be a different request, not just the same one (aka refresh didn’t cause it).

He found two ways to make it work :

  1. Commenting out the line $container->setParameter('container.dumper.inline_class_loader', true);, or
  2. Commenting out the line $kernel->loadClassCache(); in app_dev.php

I personally can't reproduce the issue on my setup. Any idea what might be happening here ?

Also, it might look like we're not the only ones : https://stackoverflow.com/questions/47617879/symfony-duplicate-class-definition-in-cache

Thanks for your help.
gnutix

Activity

rpac-tump

rpac-tump commented on Dec 5, 2017

@rpac-tump

His 1st way is ok for me, i can refresh without error.
The solution on stackoverflow doesn't work for now...

nicolas-grekas

nicolas-grekas commented on Dec 5, 2017

@nicolas-grekas
Member

I think you need to remove this line from app*.php:
https://github.com/symfony/symfony-standard/blob/3.3/web/app.php#L7

nicolas-grekas

nicolas-grekas commented on Dec 5, 2017

@nicolas-grekas
Member

Try also removing L12 btw (loadClassCache)

gnutix

gnutix commented on Dec 5, 2017

@gnutix
ContributorAuthor

@nicolas-grekas That's indeed the second solution he found. However, I'm wondering why it happens and if it's a good idea to release standard code for Symfony that provoke this issue. I don't know the caching mechanism in details, but I guess there's an impact on performance for both solutions (disabling the inline dumper or the loadCacheClass) ?

I was also thinking that these code lines in app(_dev).php are not at all documented, and it might make sense to comment them (especially if they can or should be removed under certain circumstances). WDYT ?

nicolas-grekas

nicolas-grekas commented on Dec 5, 2017

@nicolas-grekas
Member

Alternatively, can you try to turn container.dumper.inline_class_loader to false? and then to remove it?
(while reverting the previous change)

weaverryan

weaverryan commented on Dec 5, 2017

@weaverryan
Member

So are those 2 settings (loadClassCache and inline_class_loader) incompat? Is there something that needs fixing or not?

nicolas-grekas

nicolas-grekas commented on Dec 5, 2017

@nicolas-grekas
Member

There are incompatible, but that should be already handled:
https://github.com/symfony/symfony/blob/3.4/src/Symfony/Component/HttpKernel/Kernel.php#L842

dunno what's missing - maybe a PHP version check also, adding \PHP_VERSION_ID >= 70000 to the existing check.

@gnutix some more debugging hints would help (also trying this additional check please)

reopened this on Dec 5, 2017
gnutix

gnutix commented on Dec 5, 2017

@gnutix
ContributorAuthor

Setting container.dumper.inline_class_loader to false resolves the issue. Same when using:

'inline_class_loader_parameter' => \PHP_VERSION_ID >= 70000 && !$this->loadClassCache && !class_exists(ClassCollectionLoader::class, false) ? 'container.dumper.inline_class_loader' : null,

along with container.dumper.inline_class_loader set to true.

added a commit that references this issue on Dec 7, 2017

bug #25363 [HttpKernel] Disable inlining on PHP 5 (nicolas-grekas)

gnutix

gnutix commented on Dec 7, 2017

@gnutix
ContributorAuthor

Thanks Nicolas for the fix. So the idea is that the AppKernel.php codes enables it, and behind the scene it's disabled for PHP < 7. Guess that's alright for such a "not-well-know" optimization parameter, but still I find it a bit strange. We do have PHP 7 conditions in app.php/app_dev.php so it's explicit. Why not in AppKernel too ?

seblegall

seblegall commented on Dec 14, 2017

@seblegall

Thx for the fix @nicolas-grekas. We just crashed the all Meetic website due to this error. :-) I guess we will wait for the 4.4.2 to be release before upgrading to sf 3.4.

sroze

sroze commented on Dec 14, 2017

@sroze
Contributor

@seblegall You mean 3.4.2, right? 😄

seblegall

seblegall commented on Dec 14, 2017

@seblegall

Yeah, of course. ;-)

behradkhodayar

behradkhodayar commented on Jan 2, 2018

@behradkhodayar

Right after installing a SF 3.4.1 it worked fine, but only after a server restart everything crashed getting the same error!

mehdimabrouk

mehdimabrouk commented on Nov 1, 2018

@mehdimabrouk
Contributor

You can upgrade to symfony3.4.2 and resolve the problem

bennet-enqos

bennet-enqos commented on Feb 8, 2020

@bennet-enqos

I just removed the files in var/cache/prod and var/cache/dev inside the project folder. It worked for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @fabpot@weaverryan@nicolas-grekas@gnutix@sroze

      Issue actions

        [3.4] Cannot redeclare class Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser · Issue #25334 · symfony/symfony