Fatal error: Cannot redeclare balh-blah-blah (previously declared in /www/path/to/your/file/filename.php on line xxx)
The keyword in the error is "redeclare".
This means the site is parsing the file more than once. In PHP certain items can only be "defined" once (functions and classes for example). If the file they are in is parsed by the PHP processor more than once you'll probably end up with a "Cannot redeclare ...." error.
Here's how to find out where the file is getting parsed.
To show how this works and how to use it I purposely introduced a "Cannot redeclare ...." error on my WAMP server.
Here's my error:
Quote
Fatal error: Cannot redeclare class oscTemplate in F:\wamp\www\231\includes\classes\osc_template.php on line 33
Quote
Fatal error: Cannot redeclare class oscTemplate in F:\wamp\www\231\includes\classes\osc_template.php on line 33
So I go to \includes\classes\osc_template.php and I look at the code.
Every osC file has the GNU General Public License declaration at the top of the file, it looks about like this:
/* $Id$ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2010 osCommerce Released under the GNU General Public License */So I take the code below and place it just AFTER that code but BEFORE all the other code in the file:
//* * * * start of backtrace debug code * * *
$dbt = debug_backtrace();
echo "<div><br>= = = = = = = = Backtrace = = = = = = = =<br>\n";
for ( $d_b_t = 0 ; $d_b_t < count($dbt) ; $d_b_t++ ) {
if ( $d_b_t == 0 )
echo basename( __FILE__ ) . ' is referenced in ';
else {
echo $dbt[$d_b_t - 1]['file'] . ' is referenced in ';
}
if ( isset( $dbt[$d_b_t]['file'] ) ) {
echo $dbt[$d_b_t]['file'] . ' on line ';
}
if ( isset( $dbt[$d_b_t]['line'] ) ) {
echo $dbt[$d_b_t]['line'] . ' in a "';
}
if ( isset( $dbt[$d_b_t]['function'] ) ) {
echo $dbt[$d_b_t]['function'] . '"<br>' . "\n";
}
}
echo "<br>= = = = = = = = = = = = = = = = = = = = =<br>\n</div>";
//* * * * end of backtrace debug code * * *
Now I access the site with my browser.The output looks something like this:
Quote
= = = = = = = = Backtrace = = = = = = = =
osc_template.php is referenced in F:\wamp\www\231\includes\application_top.php on line 447 in a "require"
F:\wamp\www\231\includes\application_top.php is referenced in F:\wamp\www\231\index.php on line 13 in a "require"
= = = = = = = = = = = = = = = = = = = = =
.
.
.
. (more output to the browser here)
.
.
.
= = = = = = = = Backtrace = = = = = = = =
osc_template.php is referenced in F:\wamp\www\231\includes\footer.php on line 37 in a "require"
F:\wamp\www\231\includes\footer.php is referenced in F:\wamp\www\231\includes\template_bottom.php on line 43 in a "require"
F:\wamp\www\231\includes\template_bottom.php is referenced in F:\wamp\www\231\index.php on line 274 in a "require"
= = = = = = = = = = = = = = = = = = = = =
Fatal error: Cannot redeclare class oscTemplate (previously declared in F:\wamp\www\231\includes\classes\osc_template.php on line 33)
osc_template.php is referenced in F:\wamp\www\231\includes\application_top.php on line 447 in a "require"
F:\wamp\www\231\includes\application_top.php is referenced in F:\wamp\www\231\index.php on line 13 in a "require"
= = = = = = = = = = = = = = = = = = = = =
.
.
.
. (more output to the browser here)
.
.
.
= = = = = = = = Backtrace = = = = = = = =
osc_template.php is referenced in F:\wamp\www\231\includes\footer.php on line 37 in a "require"
F:\wamp\www\231\includes\footer.php is referenced in F:\wamp\www\231\includes\template_bottom.php on line 43 in a "require"
F:\wamp\www\231\includes\template_bottom.php is referenced in F:\wamp\www\231\index.php on line 274 in a "require"
= = = = = = = = = = = = = = = = = = = = =
Fatal error: Cannot redeclare class oscTemplate (previously declared in F:\wamp\www\231\includes\classes\osc_template.php on line 33)
In my case:
Quote
osc_template.php is referenced in F:\wamp\www\231\includes\footer.php on line 37 in a "require"
require(DIR_WS_CLASSES . 'osc_template.php');So I go to \includes\footer.php and I remove or "comment out" the offending code.
Then I access the site with my browser again to be certain the error is resolved.
When I'm sure the error is gone I remove the backtrace debug code.









