471,086 Members | 811 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,086 software developers and data experts.

Fatal error: Cannot redeclare...

I have a peculiar bug in my PHP code. It looks something like this:

Fatal error: Cannot redeclare func_name() (previously declared in
script.php:57) in script.php on line 57

I've done a search and determined that "func_name" really is unique.
Besides, how is this even possible? It was previously declared on the
same line it's declared?
Any help is appreciated. Thank you!

Jul 22 '08 #1
5 3435
Are you accidentally including the same file more than once?

"Just Another Victim of the Ambient Morality" <ih*******@hotmail.comwrote
in message news:Pz*********************@fe09.news.easynews.co m...
I have a peculiar bug in my PHP code. It looks something like this:

Fatal error: Cannot redeclare func_name() (previously declared in
script.php:57) in script.php on line 57

I've done a search and determined that "func_name" really is unique.
Besides, how is this even possible? It was previously declared on the
same line it's declared?
Any help is appreciated. Thank you!

Jul 22 '08 #2

"Tim McGurk" <ti*******@yahoo.comwrote in message
news:O5******************************@giganews.com ...
Are you accidentally including the same file more than once?

"Just Another Victim of the Ambient Morality" <ih*******@hotmail.com>
wrote in message news:Pz*********************@fe09.news.easynews.co m...
> I have a peculiar bug in my PHP code. It looks something like this:

Fatal error: Cannot redeclare func_name() (previously declared in
script.php:57) in script.php on line 57

I've done a search and determined that "func_name" really is unique.
Besides, how is this even possible? It was previously declared on the
same line it's declared?
Any help is appreciated. Thank you!
Thank you for the quick reply!
I don't think I'm including it more than once.
Actually, what I'm doing is this:

function func($input)
{
function func_name($e)
{
return $e + 1;
}

return array_map('func_name', $input);
}

This appears to be what's causing the error.
I would have guessed that it was okay but, apparently, defining
"func_name" in "func" decorates it, somehow. However, I read some
documentation saying that all function names have global scope, regardless
of where it was defined.
So, is this possibly a bug?
Thank you...
Jul 22 '08 #3
Just Another Victim of the Ambient Morality escribió:
function func($input)
{
function func_name($e)
{
return $e + 1;
}

return array_map('func_name', $input);
}
func_name() is declared when you run func(). That means that if you run
func() more than once you'll declare func_name() more than once, what is
not allowed.

Just move func_name() outside func(), I see no reason to declare it inside.

It looks like you've done lots of JavaScript stuff. Sorry, PHP is way
different.

So, is this possibly a bug?
Yes, it's a bug in your code ;-)

--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Jul 22 '08 #4
On Jul 22, 7:05*am, "Just Another Victim of the Ambient Morality"
<ihates...@hotmail.comwrote:
"Tim McGurk" <timmcg...@yahoo.comwrote in message

news:O5******************************@giganews.com ...
Are you accidentally including the same file more than once?
"Just Another Victim of the Ambient Morality" <ihates...@hotmail.com>
wrote in messagenews:Pz*********************@fe09.news.easy news.com...
* *I have a peculiar bug in my PHP code. *It looks something like this:
Fatal error: Cannot redeclare func_name() (previously declared in
script.php:57) in script.php on line 57
* *I've done a search and determined that "func_name" really is unique.
* *Besides, how is this even possible? *It was previously declared on the
same line it's declared?
* *Any help is appreciated. *Thank you!

* * Thank you for the quick reply!
* * I don't think I'm including it more than once.
* * Actually, what I'm doing is this:

function func($input)
{
* * function func_name($e)
* * {
* * * * return $e + 1;
* * }

* * return array_map('func_name', $input);

}

* * This appears to be what's causing the error.
* * I would have guessed that it was okay but, apparently, defining
"func_name" in "func" decorates it, somehow. *However, I read some
documentation saying that all function names have global scope, regardless
of where it was defined.
* * So, is this possibly a bug?
* * Thank you...
function func($input) {
if (!function_exists('func_name')) {
function func_name($e){{
return $e + 1;
}
}
return array_map('func_name', $input);
}

Try this!

greetz Alex
Jul 22 '08 #5
On Jul 22, 7:10*pm, "vette...@googlemail.com"
<vette...@googlemail.comwrote:
On Jul 22, 7:05*am, "Just Another Victim of the Ambient Morality"

<ihates...@hotmail.comwrote:
"Tim McGurk" <timmcg...@yahoo.comwrote in message
news:O5******************************@giganews.com ...
Are you accidentally including the same file more than once?
"Just Another Victim of the Ambient Morality" <ihates...@hotmail.com>
wrote in messagenews:Pz*********************@fe09.news.easy news.com....
>* *I have a peculiar bug in my PHP code. *It looks something like this:
>Fatal error: Cannot redeclare func_name() (previously declared in
>script.php:57) in script.php on line 57
>* *I've done a search and determined that "func_name" really is unique.
>* *Besides, how is this even possible? *It was previously declared on the
>same line it's declared?
>* *Any help is appreciated. *Thank you!
* * Thank you for the quick reply!
* * I don't think I'm including it more than once.
* * Actually, what I'm doing is this:
function func($input)
{
* * function func_name($e)
* * {
* * * * return $e + 1;
* * }
* * return array_map('func_name', $input);
}
* * This appears to be what's causing the error.
* * I would have guessed that it was okay but, apparently, defining
"func_name" in "func" decorates it, somehow. *However, I read some
documentation saying that all function names have global scope, regardless
of where it was defined.
* * So, is this possibly a bug?
* * Thank you...

function func($input) {
* * if (!function_exists('func_name')) {
* * * * * * * * function func_name($e){{
* * * * * * * * * * * * return $e + 1;
* * * * * * * * }
* * * * }
* * return array_map('func_name', $input);

}

Try this!

greetz Alex
function func($input) {
if (!function_exists('func_name')) {
function func_name($e) { // without double curly brackets
return $e + 1;
}
}
return array_map('func_name', $input);
}
Jul 22 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Tim Tyler | last post: by
12 posts views Thread by TristaSD | last post: by
1 post views Thread by Simon Kittle | last post: by
2 posts views Thread by Midgard | last post: by
4 posts views Thread by Kesavan | last post: by
1 post views Thread by srilathaapi | last post: by
2 posts views Thread by srilathaapi | last post: by
2 posts views Thread by ann86 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.