Track down ErrorException: Fatal Error: Cannot redeclare class

LPH

Well-known member
A WordPress widget is conflicting with numerous XenForo add-ons. Each stating a class cannot be redeclared. If the widget is removed then the WordPress page loads properly. There are about 5 different XF add-ons conflicting.

This is the main part of the widget code. Somewhere in the reasoning, there is a reattempt to redeclare classes from XF add-ons but I don't see it.

PHP:
        $dependencies = new XenForo_Dependencies_Public();

        $dependencies->preLoadData();

        /** @var  $sessionModel XenForo_Model_Session */
        $sessionModel = XenForo_Model::create( 'XenForo_Model_Session' )->getModelFromCache('XenForo_Model_Session');

        $visitor = XenWord::getVisitor();

        /** Pull onlineUsers */
        $onlineUsers = $sessionModel->getSessionActivityQuickList(
            $visitor->toArray(),
            array( 'cutOff' => array( '>', $sessionModel->getOnlineStatusTimeout() ) ),
            ( $visitor['user_id'] ? $visitor->toArray() : null )
        );

        echo "<span class='xenword-onlineusers'>";
        echo 'Total: ' . $onlineUsers['total'] . ' (members ' . $onlineUsers['members'] . ', guests: ' . $onlineUsers['guests'] . ', robots: ' . $onlineUsers['robots'] . ')';
        echo "</span><br />";

Is there anything obviously wrong with the above code?
 
PHP:
/** @var $sessionModel XenForo_Model_Session */
 $sessionModel = XenForo_Model::create( 'XenForo_Model_Session' )->getModelFromCache('XenForo_Model_Session');

Aside from the fact this line is redundant, no. The problem with this line is that you're creating the model just to get it from cache (which is meant to be used to prevent creating it when unnecessary to begin with).

Could you post the full stack trace?
 
Thank you @Daniel Hood -- Here is the only information available in the /admin.php under server errors.

Code:
ErrorException: Fatal Error: Cannot redeclare class XFCP_Dark_PostRating_Model_Session - library/XenForo/Application.php(528) : eval()'d code:1
Generated By: Unknown Account, Sunday at 9:59 PM
Stack Trace
#0 [internal function]: XenForo_Application::handleFatalError()
#1 {main}
Request State
array(3) {
  ["url"] => string(117) "http://www.tuxreports.com/techquestions/technology/windows-vista/106920-help-w-vista-folder-views-reward-offered.html"
  ["_GET"] => array(0) {
  }
  ["_POST"] => array(0) {
  }
}

This page (
http://www.tuxreports.com/techquest...help-w-vista-folder-views-reward-offered.html)
has the WordPress widget on it that is causing the error.
 
Last edited:
Could you please let us know which add-ons are conflicting with your widget?

I assume that there is no problem if you create the model with the new operator instead of the create() method. If so, this could at least be a workaround...
 
Looking at the error, it looks to me like you have delcaired said class name more than once. Can you please post the whole code?
 
It's because you're preloading the data again, invalidating previous data and causing classes to be re-created. That's my current guess at least, from my memory of how the dependencies system works.

Liam
 
Top Bottom