Forum Moderators: coopster

Message Too Old, No Replies

Fatal error: Cannot redeclare

where to look to fix

         

Fallen Angel

11:49 am on Mar 16, 2008 (gmt 0)

10+ Year Member



Hi, please could someone help with this problem. Have searched the forums for Fatal Error: and although finding many posts I can't work out what I should be looking for!

I have learnt that the Fatal Error: message seems to mean that there is a duplicate somewhere which needs to be sorted but I don't know where to look to sort the problem (am not too clued up on this you can tell).

I think the clue is in the error message but if I go to that file I'm not sure what to look for or what to alter or what to alter it to!
Any help would be very much appreciated.

Fatal error: Cannot redeclare class currencies in /includes/classes/currencies.php on line 16

Habtom

12:08 pm on Mar 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your best bet is to check if you haven't included the file twice anywhere, or you are not including a file which is including another file included in your page.

Fallen Angel

12:17 pm on Mar 16, 2008 (gmt 0)

10+ Year Member



Thank you for your reply and advice but I don't understand how this file may have changed as I didn't do anything with this file.

Could you please explain what >>not including a file which is including another file included in your page means as I'm new to this and am not sure what this sentence means.

Many thanks

cameraman

6:19 pm on Mar 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The error is telling you that the class has already been defined and you're trying to define it again. As Habtom said, this most often happens when the file that defines the class gets included more than once.
Let's say you have three files, globals.php, currencies.php, and view.php. Here are their partial contents:

globals.php
<?php
include "currencies.php";
$sitename='example.com';
$sitepath='/home/user/example';
?>

currencies.php
<?php
class currencies {
public $conversion;
public $last_result;
public function convert($amountt) {
}
}
?>

view.php
<?php
include 'globals.php';
include 'currencies.php';

$currency = new currencies;
?>

view.php includes globals, which includes currencies. Then view.php includes currencies itself, which will generate the error you describe. To fix it, you'll need to start at the script you're trying to load into your browser and backtrack each of the files it includes to see where currencies is getting included. You may be able to fix it by changing each of the include directives to include_once [us.php.net].

Fallen Angel

11:26 am on Mar 19, 2008 (gmt 0)

10+ Year Member



Thank you for your help.
In the file that was having a problem I changed require to requir_once and it worked like a charm.

Thanks for the explanation too, it makes it a little easier to try to learn.

Many thanks to everyone, your help is very much appreciated.

Fallen Angel

11:27 am on Mar 19, 2008 (gmt 0)

10+ Year Member



errrmmmmm !

typo - I changed it too require_once

Sorry