phpmagentoredeclare

Cannot redeclare class Magento


I have an interesting issue. The front-end of my website loads fine, however when I try to navigate to:

domain.com/index.php/admin

I get a white page. I have enabled debugging mode and it displays this error:

Array ( [type] => 64 [message] => Cannot redeclare class Mage_Admin_Model_Session [file] => /var/www/vhosts/domain.co.uk/sub-domain.co.uk/includes/src/__adminhtml.php [line] => 504 )

Since finding this new error, I've tried to comment/remove every class that it cannot redeclare in the __adminhtml.php file, one by one.. Only to find that by the time I've commented them all out and refreshed the admin page, it gives no error whatsoever. Just a white page.

Any ideas?


Solution

  • Here are some debugging tips you could try to find the cause of the problem.

    This snippet will show you where a given class is previously defined:

    $className = 'Foo';
    if ( class_exists( $className ) ) {
      $rc = new ReflectionClass($className);
      print __FILE__.':'.__LINE__. ": Class $className already defined in " 
        . $rc->getFileName() . ":" . $rc->getStartLine();
    }
    

    You can do the same for functions; just use function_exists and ReflectionFunction instead.

    It looks like somewhere a file is included/required twice. If it is the __adminhtml.php file that is included once too often, you can add a call to debug_print_backtrace() to see where it's being included from.

    Also, If you have customized files, you could use require_once instead of require.