1. 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

Discussion in 'XenForo Development Discussions' started by LPH, Feb 22, 2016.

  1. LPH

    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.

            $dependencies = new XenForo_Dependencies_Public();


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

    $visitor XenWord::getVisitor();

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

    "<span class='xenword-onlineusers'>";
    'Total: ' $onlineUsers['total'] . ' (members ' $onlineUsers['members'] . ', guests: ' $onlineUsers['guests'] . ', robots: ' $onlineUsers['robots'] . ')';
    "</span><br />";
    Is there anything obviously wrong with the above code?
  2. Daniel Hood

    Daniel Hood Well-Known Member

    /** @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?
    Robust and Thomas.B like this.
  3. LPH

    LPH Well-Known Member

    Thank you @Daniel Hood -- Here is the only information available in the /admin.php under server errors.

    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 (
    has the WordPress widget on it that is causing the error.
    Last edited: Feb 24, 2016
  4. Thomas.B

    Thomas.B Well-Known Member

    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...
  5. wang

    wang Well-Known Member

    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?
  6. Liam W

    Liam W Well-Known Member

    Where is this being called?

    Are you calling the startApplication method?

  7. LPH

    LPH Well-Known Member

    That's what the message states but I cannot track down any place this is called more than once.

    Sorry to not have answered. This is in a WordPress widget outside of XenForo.
  8. Liam W

    Liam W Well-Known Member

    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.


Share This Page