Fatal error: Cannot declare class Ctct\CTCTOfficialSplClassLoader
-
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 23I 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.phpneeds to be changed torequire_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
CTCTOfficialSplClassLoaderclass 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.
The topic ‘Fatal error: Cannot declare class Ctct\CTCTOfficialSplClassLoader’ is closed to new replies.