tags:

views:

160

answers:

7

I received the following error:

[27-Apr-2009 10:26:06] PHP Fatal error:  Cannot redeclare alphanumeric() (previously declared in /home/iddoc/public_html/lib/common.php:6) in /home/iddoc/public_html/lib/common.php on line 8

Notice this:

/home/iddoc/public_html/lib/common.php:6) in 
/home/iddoc/public_html/lib/common.php on line 8

Here are the offending lines:

function alphanumeric($str) {
    return strtolower(preg_replace("/[^A-Za-z0-9]/",'',$str));
}

Prior to these lines there are only comments. There is no other declaration of that function anywhere else in that file or any other.

Strange, no?

+8  A: 

Are you using require_once() to include common.php everywhere? If you use just require or include, that will cause this issue.

Matt
+4  A: 

Are you using require/include to reference the file? This is a common error when including a file twice. PHP doesn't know what to do if it sees two declarations, even if they're from an identical file.

Try using this:

include_once('lib/common.php');
ojrac
A: 

Check for recursive includes and make sure your blocks are not executed several times.

Anton Gogolev
+1  A: 

Sounds like you've got the common.php file included more than once. Do you use include(), require() or require_once() for your includes?

AlexanderJohannesen
+2  A: 

It seems like you may have included the common.php file more than once. The second time it loaded would cause errors like that since the function is already loaded.

It is an odd error, but will probably seem logical once the problem is figured out. I would suggest looking at your includes, or switch them to include_once. Maybe see what debug_print_backtrace() outputs before that function loads.

Brent Baisley
+1  A: 

is this common.php included earlier? That could cause this error.

+1  A: 

You should always use include_once or require_once when including code files in PHP. There are exceptions to this rule but if you aren't sure, use the _once versions. The only time it is okay to use include or require is when you know the file will never, ever be included again in the same program OR the file being included does not declare functions (without protecting them with an if (function_exists()) {} block).

As an example, templating system are one of the very few uses where you probably don't want the _once version.

jmucchiello