8000 Problem with the cache warmer: Cannot redeclare class Event · Issue #29216 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Problem with the cache warmer: Cannot redeclare class Event #29216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
LorisZ opened this issue Nov 14, 2018 · 4 comments
Closed

Problem with the cache warmer: Cannot redeclare class Event #29216

LorisZ opened this issue Nov 14, 2018 · 4 comments

Comments

@LorisZ
Copy link
LorisZ commented Nov 14, 2018

Symfony version(s) affected: 3.4.18 with php 5.6

Description
After clearing the cache, when trying to access any web page of the application, the following Fatal Error occurs: Fatal error: Cannot redeclare class Symfony\Component\EventDispatcher\Event in ./var/cache/prod/classes.php on line 4471. This happens only in prod environment.

When clearing the cache, the file classes.php is created and contains the class Symfony\Component\EventDispatcher\Event, which seems to be unwanted, because it's already been loaded from vendor.

When deleting the file classes.php from var/cache/prod/ and making the cache writable for apache, the automatically generated file does NOT contain the Event class and everything works.

How to reproduce
I'm not sure what changed in the last couple of weeks, when I was still on 3.4.17 it worked, but simply changing the version in composer.json back to 3.4.17 did not solve the problem.

Possible Solution
I think when creating the cache from command line, the class Event for some reason already exists and the warmer takes all the declared classes and puts them in to classes.php. I don't know why from command line and only in prod environment the class exists but otherwise not.

@linaori
Copy link
Contributor
linaori commented Nov 14, 2018

Having op-cache, I don't think you need to be using that class cache in the first place. You should be able to safely disable it.

@Tobion
Copy link
Contributor
Tobion commented Nov 15, 2018

If you have problems with this class cache, I can also suggest to remove it. see #20668

@LorisZ
Copy link
Author
LorisZ commented Nov 15, 2018

Since we're still on php5.6 for now, I think we still profit from the cache. Or not?

We still had some classes without namespace and migrated them to classes with Namespace, and included a class_alias for the old classes for backwards compatibility, and put those files in autoload-files in composer.json. Those files contained some references to the Event-class in question.

Instead of relying on the fallback, we simply changed all references to the new Classnames and removed the old files. Doing that, it works now, but I'm still not sure why that caused the Event class to be written into classes.php. One of the classes that was in one of those files extended the Event, so I guess that was the reason it was loaded, but still not sure why it was written into classes.php (the other - our classes - were not).

@javiereguiluz
Copy link
Member

Closing this issue because, as explained in the last comment, it looks like some temporary issue caused by introducing namespaces in some classes. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
0