XF 1.5 Cannot redeclare class

LPH

Well-known member
This is a challenge (for me). I have code which has worked for years. It was copied into a new version of the WordPress plugin which uses Composer and namespace.

PHP:
/** @var $countersModel \XenForo_Model_Counters */
$countersModel = \XenForo_Model::create( 'XenForo_Model_Counters' );
$total_counts = $countersModel->getBoardTotalsCounter();

The $total_counts line is the issue. If it is commented out then the error is not present. Of course, I cannot get the information needed for board totals ...

This is the error:

Code:
ErrorException: Fatal Error: Cannot declare class [insert name of XF addon], because the name is already in use - library/XenForo/Application.php(528) : eval()'d code:1

It isn't every XF addon, and as soon as I disable the specific XF addon then the error goes away.

This is obviously not acceptable. I was thinking something in the connector is wrong and causing conflicts with XF add-ons. The connector is almost exactly like the index.php file in XenForo.

PHP:
/**
* absolute_path is set in XenWord Settings
* Use phpinfo() in XenForo admin to get the absolute path
* /admin.php?tools/phpinfo
*/
if ( ! class_exists( 'XenForo_Autoloader' ) ) {

   if ( $this->options['use_xenword_xf2'] == true || $this->options['absolute_path'] == '' ) {
      return false;
   }

   $startTime = microtime( true );

   /** @var $fileDir */
   $fileDir = $this->options['absolute_path'];

   require_once( $fileDir . '/library/XenForo/Autoloader.php' );
   \XenForo_Autoloader::getInstance()->setupAutoloader( $fileDir . '/library' );

   \XenForo_Application::initialize( $fileDir . '/library', $fileDir, true, array( 'resetOutputBuffering' => false ) );
   \XenForo_Application::set('page_start_time', $startTime );
   \XenForo_Application::disablePhpErrorHandler();

   $this->enableErrorReport();
}

if ( empty( $GLOBALS['xfLoaded'] ) ) {
   // These are needed to make sure that XenForo addons
   global $dependencies;
   $dependencies = new \XenForo_Dependencies_Public();
   $dependencies->preLoadData();

   \XenForo_Session::startPublicSession( new \Zend_Controller_Request_Http );

}

Removal of the $dendencies didn't work, either.

Does anyone have any suggestions on what to look for? Or a suggestion on how to track down the problem.
 
Interesting. The lines were changed to the following:

PHP:
$total_counts = \XenForo_Model::create( '\XenForo_Model_Counters' )->getBoardTotalsCounter();

And there is no error when the other Addon is enabled.

Can anyone explain why this would be the case?
 
Back
Top Bottom