Solving the error "Fatal error: Cannot redeclare"

  • Solving the error "Fatal error: Cannot redeclare"

If after installing a module or modifying on Opencart 2 you get an error Fatal error: Cannot redeclare ... - this means that the php function or php class specified in the error is duplicated. You need to leave only one function or class with that name. It's very simple, look for the problematic file (controller or model, most likely modified via vqmod or ocmod) that is specified in the function, in this file look for functions or classes with the same name and if they are completely duplicated - then delete one of them, if they different - rename and correct the entire chain of calls to this function or class.

Error example:
Fatal error: Cannot redeclare ModelCatalogProduct::editList() in /home/site/public_html/www.site.com/vqmod/vqcache/vq2-admin_model_catalog_product.php on line 164
Error solution:
Open file vqmod/vqcache/vq2-admin_model_catalog_product.php and search for "public function editList", you will find two functions with that name. Next, you need to determine: are these functions the same or different? Then you need to find in which modifier the duplicate function is added, for this open the vqmod/xml/ folder and look for the file in which this function is added. When already found: if the functions were the same - then remove this operation from the modifier, if different - rename and correct the chain of calls to this function in the module.

If such an error occurs in the system/modification/ folder or in system/storage/modification/ - the procedure is the same, only the addition of a duplicate function must be looked for in the module modifier ( file with *.ocmod.xml extension or install.xml file), then remove the old modifier in the admin panel and install the new edited one.