Fatal error: Cannot declare class ComposerAutoloader
-
Out of the blue i get this fatal error when trying to activate this awesome plugin:
[18-Apr-2023 13:09:47 UTC] PHP Fatal error: Cannot declare class ComposerAutoloaderInitfaf42c5f235c65e8397793ae676be6da, because the name is already in use in /Users/nicb/_htdocs/mybricks2023/wp-content/plugins/query-monitor/vendor/composer/autoload_real.php on line 5but i used it before in the same project. what could be the cause / source of the problem?
-
i already remove it entirely and installed it again. i disabled every other plugin. always getting this error.
Is there a
wp-content/db.phpfile in place on your site? If so, does it belong to Query Monitor? If so, can you try deleting it please and then reactivating Query Monitor?Let me know how it goes.
holy sh*t this was the issue! i mean it was there but i removed it now then activated query monitor again and voila its working again! thank you a million @johnbillion !!
So that’s an issue that’s popped up a handful of times in the last decade or so and as far as I can tell it’s due to due the opcode cache on the server not always handling symlinks correctly. I’ve never had a chance to look into it because it goes away as soon as the file is deleted.
Glad that was the issue.
I’m having same issue on my staging site. I tried deleting wp-content/db.php both in main wp-content folder and (strangely) a wp-content folder in Query Monitor plugin folder. Didn’t help.
A side note, Query Monitor runs perfectly on my live site.
The problem is that query-monitor creates an *absolute* link to the db.php file out of your wp-content. Then if you clone the site or copy it elsewhere, this link can point to somehwere you don’t hvae permission to.
My db.php looked like this:
db.php -> /home/olduser/public_html/wp-content/plugins/query-monitor/wp-content/db.phpand it was red and angry because the newuser did not have access.
I removed the symlink and re-added it relative instead:
rm db.php ln -s plugins/query-monitor/wp-content/db.phpif the plugin were to add the symbolic link this way (using a relative path to the wp-content folder) then it would not be so fragile and blow up when the site was cloned.
Unfortunately using a relative symlink by default isn’t an option for two reasons:
- The
symlink()function in PHP cannot create a relative symlink on a Windows environment. - It’s not guaranteed that a relative path can be found between the
wp-contentdirectory and thedb.phpfile in the plugin, for example if the plugin directory points elsewhere via theWP_PLUGIN_DIRconstant. This is much more common than you might think.
I just encountered this issue as well when I deployed my staging site to live: it crashed the site due to the symlink being absolute. I understand what you’re saying about using a relative symlink not being possible. I wonder if it’s worth at least printing an admin notice about this when the plugin is first activated, to warn users in case they move their site that they may need to update or recreate the link?
Alternatively, is there a way to make the plugin work without this symlink? Can it find and use the actual
db.phpin the plugin directory?You can delete the db.php file complete and QM will work fine, just with a little less info.
I will try to find some time to look into how to avoid a fatal error under this condition.
I have the same issue, deleting db.php change anything
Fatal error: Cannot declare class ComposerAutoloaderInitad25d53a23099da4b0886b4f6754360e, because the name is already in use in /var/www/html/wordpress/…/plugins/query-monitor/vendor/composer/autoload_real.php on line 5
Can you provide a list of the plugins that are active on your site please?
Same problem. Deleting db.php doesn’t help.
List of active plugins on site…ad-inserter
admin-user-message
all-in-one-wp-migration
antispam-bee
aryo-activity-log
broken-link-checker
classic-editor
companion-auto-update
generateblocks
generateblocks-pro
google-sitemap-generator
gp-premium
index.php
insert-headers-and-footers
mailgun
query-monitor
setowp
wordpress-importer
wordpress-seo
wordpress-seo-premium
wp-fail2ban
wp-fastest-cache
wp-smushit
wpforms-lite
wpmudev-updatesI’m use to working on the command line, so if there’s any fix you’d like tested, pass it along + I’ll report back what occurs.
File containing this class include…
ack -ilr ComposerAutoloaderInitad25d53a23099da4b0886b4f6754360e .
query-monitor/vendor/autoload.php
query-monitor/vendor/composer/autoload_real.phpoh man, it took me ridiculously long time to figure this out! Lots of conversations with ChatGPT to giving up and googling and getting all the way to this post by John:
“Is there a
wp-content/db.phpfile in place on your site? If so, does it belong to Query Monitor? If so, can you try deleting it please and then reactivating Query Monitor?”When they say there is this “one weird trick” to fix it all then here is the example of it.
THANK YOU.
- The
The topic ‘Fatal error: Cannot declare class ComposerAutoloader’ is closed to new replies.