Cannot redeclare class

From Zen Cart(tm) Wiki
Jump to: navigation, search

Fatal error: Cannot redeclare class NameOfYourFileHere in path\to\the\NameOfYourFileHere.php on line XX

This error sometimes appears after installing hacks or making certain other edits to your cart's files. Each page must process the code contained in the path/to/NameOfYourFileHere.php file once. If a page tries to process this code a second time, the error above appears.

Fortunately, this is an easy error to fix. First, you need to locate this line in your NameOfYourFileHere.php file.


   class NameOfYourFileHere { 

Now add this code before the line you just found...


  if ( class_exists('NameOfYourFileHere') ) 

The new code will prevent repeated processing of includes/NameOfYourFileHere.php and therefore put an end to this error. Many thanks to the folks in the PHPBB forums for helping me with this code - applied it to my cart and it worked like a charm.

I do not know of any security issues raised by this fix... f anyone knows why this should NOT be used please speak up!