Bad Boy Blog, an unofficial Diddy and Bad Boy fan blog

Bookmark and Share

Cannot Redeclare Function error

Cannot Redeclare Function error

Postby Thoul » April 7th 2005, 12:31 am

Fatal error: Cannot redeclare function_name() (previously declared in file.php:10) in file.php on line 10


A variation of this error message sometimes appears after installing hacks or making certain other edits to your forum's files. In order to perform the variety of tasks that go into managing and displaying a forum, each page must process code stored in several different files. When this error is displayed, it is an indication that some code is either being processed twice or shares a name with another area of code.

To determine which case you are dealing with, compare the two file names mentioned in the error message. These are shown in green and red text in the example. When the two filenames are identical, this indicates that the page is attempting to process the named file more than once. Look at Case 1 below for a solution. If the two filenames are different, two pieces of code are sharing a name; this is covered in Case 2.
Last edited by Thoul on April 7th 2005, 12:38 am, edited 2 times in total.
User avatar
Thoul
Admin/Webmaster
 
Posts: 18551
Joined: July 30th 2002, 11:30 am
Location: USA

Postby Thoul » April 7th 2005, 12:32 am

Case 1: Processing a File Twice

The first step to fixing the error is to locate a certain line in the indicated file. The exact line you must find will vary from one instance of this problem to another, but the error message will give you two hints to help locate the line. Notice that in the example error message, the text function_name is bolded. Your error message will have something different in the place of function_name. Examples might be "get_userdata," "make_realdate" or "message_die." You need to locate a line that begins like this, replacing function_name with the matching text from your error message:
function function_name(


So examples of the actual line to locate could be any of the following:
function get_userdata(
function make_realdate(
function message_die(


Remember that you will be trying to find a line that begins with this text. In 99% of cases, there will be more text following this on the same line.

Once you have found the line, add the code below before it. Again, replace function_name with the text from the error message. Take care to match spelling exactly and preserve the single quotation marks.
Code: Select all
if ( function_exists('function_name') )
{
	return;
}


The new code will prevent repeated processing of the file and put an end to the error.
User avatar
Thoul
Admin/Webmaster
 
Posts: 18551
Joined: July 30th 2002, 11:30 am
Location: USA

Postby Thoul » April 7th 2005, 12:42 am

Case 2: Sharing a Name

On rare occasions, you might actually run into a case where some newly added hack is conflicting with existing code in phpBB or another installed hack. These are more difficult to fix than Case 1 errors because they tend to vary even more from case to case. If you are not an experienced PHP programmer that understands the flow of the files and code involved, it is better to seek assistance from the author of the hack you have recently added or the Support Forums than to attempt to fix this error yourself. At least two changes will likely be required, but many cases may require several more changes than this.
User avatar
Thoul
Admin/Webmaster
 
Posts: 18551
Joined: July 30th 2002, 11:30 am
Location: USA


Return to phpBB 2: Troubleshooting

Who is online

Users browsing this forum: No registered users and 0 guests