• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Track down ErrorException: Fatal Error: Cannot redeclare class

LPH

Well-known member
#1
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?
 

Daniel Hood

Well-known member
#2
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?
 

LPH

Well-known member
#3
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:

Thomas.B

Well-known member
#4
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...
 

wang

Well-known member
#5
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?
 

Liam W

Well-known member
#8
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