Support » Plugin: WP Debugging » WPConfigTransformer class redeclaration fatal error

  • Resolved jofbe

    (@bencico)


    Hi,
    I would like to be able to use this plugin on a few sites, where I have other plugins activated, that would try to define the WPConfigTransformer class as well as this plugin (eg. Duplicator Pro). The problem is, that in this plugin the declaration is not wrapped in an if (!class_exists('WPConfigTransformer')) statement, causing the whole site to crash until I can remove the plugin folder via FTP. Could you please solve this issue?
    Ben

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Andy Fragen

    (@afragen)

    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.

    Plugin Author Andy Fragen

    (@afragen)

    Can you share the complete stack trace or error?

    Plugin Author Andy Fragen

    (@afragen)

    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 8 months, 1 week ago by Andy Fragen.
    Plugin Author Andy Fragen

    (@afragen)

    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.

    Plugin Author Andy Fragen

    (@afragen)

    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.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘WPConfigTransformer class redeclaration fatal error’ is closed to new replies.