• Resolved benmoreassynt2

    (@benmoreassynt2)


    A few people have reported a bug where a fatal error crashes their site following upgrade to version 2+. It appears likely to relate to other plugins that interact with Constant Contact Forms causing the class to be autoloaded multiple times via SplClassLoader.php

    The error I encountered is as follows:

    Fatal error: Cannot declare class Ctct\CTCTOfficialSplClassLoader, because the name is already in use in /path/to/wordpress/wp-content/plugins/constant-contact-forms-corrupt/includes/Ctct/SplClassLoader.php on line 23

    I encountered the problem yesterday, and seeing as there wasn’t a fix yet from the plugin developers, I looked into the code.

    The fix is easy. Line 141 of /wp-content/plugins/constant-contact-forms-corrupt/includes/Ctct/SplClassLoader.php needs to be changed to

    require_once ($this->includePath !== null ? $this->includePath . DIRECTORY_SEPARATOR : '') . $fileName;

    The current code uses ‘require’ instead of ‘require_once’, which means that more than one attempt to call the CTCTOfficialSplClassLoader class will result in an attempt to include the SplClassLoader.php file multiple times, and what appears to PHP to be an illegal redeclaration of a class name. Third party plugins are likely to cause the class to be instantiated additional times.

    Obviously this needs to be fixed asap in the plugin as it will currently cause a lot of sites to have fatal errors on every page.

    You might also consider whether the plugin needs to be intialized everywhere, with the associated risk of white screens of death for an entire website if the plugin has an unexpected problem.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Constant Contact

    (@constantcontact)

    Hi

    A number things here.

    1) We were having very odd issues with trying to find SplClassLoader alone when the users’ installs were apparently looking for CTCTOfficialSplClassLoader We couldn’t figure out how or why, but on the offchance that it’d work, we re-named the class to match and that cleared up issues for those users.

    2) Normally the SplClassLoader is auto generated, last I knew, but were doing a special case at the time before version 2.0.0 when we still bundled our PHP SDK. That said, with the 2.0.0 release and the API changes, we no longer needed that SDK but kept a couple of components. The require vs require_once isn’t a part that we coded ourselves.

    3) Is this constant-contact-forms-corrupt naming coming from you, as perhaps attempts to troubleshoot or have multiple copies of the plugin installed at the same time?

    Thread Starter benmoreassynt2

    (@benmoreassynt2)

    Hi, this is still a problem. I’ve narrowed down the problem to an interaction with the plugin MemberPress Constant Contact (memberpress-constantcontact).

    It is likely that both plugins are not required, and/or that the error lies in MemberPress’s code, however it might be worth including a check in your code to prevent MemberPress causing this error if both plugins happen to be activated.

    In particular, the memberpress-constantcontact plugin includes a version of the Ctct namespaced files, using the same namespace, and the SplClassLoader class. This is obviously going to run the risk of a clash of namespaced code and (from PHP’s perspective) an attempt to reload a class that has already been loaded.

    I haven’t been through the code to work out exactly where the problem is triggered, but since both plugins are initializing the ‘same’ autoloader for the ‘same’ classes, a clash seems inevitable.



    Plugin Author Constant Contact

    (@constantcontact)

    Noted on all this. We don’t presently have access to a copy of their addon, so it’s hard to test/confirm conflict resolution.

    That said, just to be certain, are you on the latest version of our plugin here?

    Did you see this changelog item below from MemberPress’ page for their Constant Contact addon? or is it possible that this is where some conflicts were introduced? Looks like this changelog item is from about 4 days before this thread here got started.

    1.1.4 – 06/16/2023
    * Fix autoloader conflict

    Thread Starter benmoreassynt2

    (@benmoreassynt2)

    Hi, yes I’m on Memberpress Constant Contact version 1.1.4, running PHP 8.1, with fully updated WordPress. I’ll see if I can pass a message to them via my client’s account.

    Plugin Author Constant Contact

    (@constantcontact)

    Sounds good, curious to hear what they have to say on the topic.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Fatal error: Cannot declare class Ctct\CTCTOfficialSplClassLoader’ is closed to new replies.