0

Problem

Following compilation, I get the error Cannot redeclare class Mage_Catalog_Model_Productwhen accessing the admin panel. Per this question, I attempted to clear the cache by deleting the cached folders (currently just using Magento's file-based caching to isolate the problem) and disabled all third-party modules to make sure that those weren't the problem.

At first I thought that for some reason the core files were getting loaded in addition to the compiled ones, but that doesn't appear to be the case.

To try to isolate the issue, I added the following code to index.php file (root) and then ran a grep on the get_included_files() files for Mage_Catalog_Model_Product -- it appears only in __adminhtml.php (though the file in which the class may be redeclared may not be included in the get_included_files() output because this is where it is choking.

ini_set('error_reporting', E_ALL);
register_shutdown_function("fatal_handler");
function fatal_handler() {
    $error = error_get_last();
    echo("<pre>");
    print_r($error);
    var_dump(get_included_files());
}

The resulting error:

Array
(
    [type] => 64
    [message] => Cannot redeclare class Mage_Catalog_Model_Product
    [file] => /Users/pbirnie/sites/city-gear/includes/src/__adminhtml.php
    [line] => 2065
)

I also grepped for the class declaration and only see it in 5 files -- __adminhtml.php seems to be the only one that is actually loading...

pbirnie:src pbirnie$ find . -name "*.php" | xargs -n 20 grep 'class Mage_Catalog_Model_Product '
./__adminhtml.php:class Mage_Catalog_Model_Product extends Mage_Catalog_Model_Abstract
./__catalog.php:class Mage_Catalog_Model_Product extends Mage_Catalog_Model_Abstract
./__checkout.php:class Mage_Catalog_Model_Product extends Mage_Catalog_Model_Abstract
./__cms.php:class Mage_Catalog_Model_Product extends Mage_Catalog_Model_Abstract
./Mage_Catalog_Model_Product.php:class Mage_Catalog_Model_Product extends Mage_Catalog_Model_Abstract

I'm currently running Magento Enterprise 1.13.1 if that is of consequence; I do not have APC or Memcached running..

0

Not a detailed answer, but in case someone else runs into this issue on EE 1.13.1, upgrading to 1.14.0.1 resolved the issue.

UPDATE

This may have been because the existing stat directory inside of the includes folder was removed - I still had the same issue on the staging environment after upgrading. Removing the stat directory took care of it.

Admin Controller Override Issue (3/2017)

I recently helped someone else with this and we ran across another possibility. In this particular case, a third-party extension was attempting to override an admin controller. The code was as follows:

require_once(Mage::getModuleDir('controllers', 'Mage_Adminhtml') . DS . 'Catalog' . DS . "ProductController.php");

This works fine until the code is compiled as it will still reference the original file (thus causing a class redeclaration error).

Changing the above code to

require_once "Mage/Adminhtml/controllers/Catalog/ProductController.php"; will reference the file in the compilation directory and thereby only included once.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.