What other plugins are declaring this class and how are they doing it?
This plugin uses composer as an autoloader and it shouldn’t be an issue. The issue would come from a plugin that directly loads that class.
The other plugin is Duplicator pro. They use the class_exists function, but since their plugin is initialized before WP Debugging, the class is declared by them, and composer doesn’t seem to care about that, therefore the error happens.
Can you share the complete stack trace or error?
Have you tried cross-posting this issue on the Duplicator forum?
The modern technique is to use an autoloader and I’m not certain what’s happening in the interaction as I don’t have access to this plugin.
I’m simply using a composer require to include this library in my plugin.
-
This reply was modified 6 years, 6 months ago by
Andy Fragen.
Here’s the issue. I’m using the wp-cli/wp-config-transformer library and including it, via composer, in my project. https://github.com/wp-cli/wp-config-transformer
Duplicator happens to have the identical class name with different code. The simplest solution would be on the Duplicator side to either rename their custom class or use namespacing. Any change on my side could cause my plugin to use code it’s not expecting.
The exact error is: Fatal error: Cannot declare class WPConfigTransformer, because the name is already in use in /var/www/project/public/wp-content/plugins/wp-debugging/vendor/wp-cli/wp-config-transformer/src/WPConfigTransformer.php on line 6
Yes, I’ve contacted the duplicator team as well, and they said:
Unfortunately, I can’t solve the problem because Duplicator already performs this type of check.
This is the portion of the code in which the class in duplicator is defined
—
if (!class_exists('WPConfigTransformer')):
/**
* Transforms a wp-config.php file.
*/
class WPConfigTransformer {
.
.
.
—
is wp-debugging that does not perform this type of check and must be resolved.
You could resolve this request to the wp-debugger creator and temporarily add this “if” where the class is defined in wp-debugger
Thanks.
You should link your discussion with the Duplicator folks here. I’m happy to discuss it with them.
As I stated above, I’m using the WP-CLI library and it’s not the same code as Duplicator has. The whole idea behind composer is that I don’t need to maintain WP-CLI’s library and given that this is for WP-CLI you would need to create an issue on their GitHub repository referenced above.
Duplicator should properly namespace their custom code and this issue wouldn’t exist. It’s not as simple as just checking class_exists.