473,795 Members | 2,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3674
Are you accidentally including the same file more than once?

"Just Another Victim of the Ambient Morality" <ih*******@hotm ail.comwrote
in message news:Pz******** *************@f e09.news.easyne ws.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!

Jul 22 '08 #2

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

"Just Another Victim of the Ambient Morality" <ih*******@hotm ail.com>
wrote in message news:Pz******** *************@f e09.news.easyne ws.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:5 7) 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...@hotm ail.comwrote:
"Tim McGurk" <timmcg...@yaho o.comwrote in message

news:O5******** *************** *******@giganew s.com...
Are you accidentally including the same file more than once?
"Just Another Victim of the Ambient Morality" <ihates...@hotm ail.com>
wrote in messagenews:Pz* *************** *****@fe09.news .easynews.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_exis ts('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...@googl email.com"
<vette...@googl email.comwrote:
On Jul 22, 7:05*am, "Just Another Victim of the Ambient Morality"

<ihates...@hotm ail.comwrote:
"Tim McGurk" <timmcg...@yaho o.comwrote in message
news:O5******** *************** *******@giganew s.com...
Are you accidentally including the same file more than once?
"Just Another Victim of the Ambient Morality" <ihates...@hotm ail.com>
wrote in messagenews:Pz* *************** *****@fe09.news .easynews.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:5 7) 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_exis ts('func_name') ) {
* * * * * * * * function func_name($e){{
* * * * * * * * * * * * return $e + 1;
* * * * * * * * }
* * * * }
* * return array_map('func _name', $input);

}

Try this!

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
9997
by: Tim Tyler | last post by:
I'm getting fatal errors when executing code - and my error handler is failing to trap them - so I get no stack backtrace :-( The error I am getting is: "Fatal error: Call to a member function fetchRow() on a non-object." What are the available options here? Am I supposed to check I have a real object whenever I perform
0
2119
by: Rich | last post by:
I am trying to obtain more debugging information for an issue I reported (ref. Bug #37185 <http://bugs.php.net/bug.php?id=37185&edit=2>). Unfortunately, I do not have access to the now-ancient Microsoft Visual C++ 6.0, which is why I cannot use the pre-built debug sysbol files for debugging. So it appears I must build PHP. I grabbed build php5.1-200605011630 earlier today, but am having build problems. My environment is Windows XP SP2,...
12
3015
by: TristaSD | last post by:
Hi, Here's a nice footer I get inside every php page I write in wwwroot on my server. The code gets parsed just fine. I installed php5.2-win32 under W2K Server, IIS 5.0. I've installed php on XP machines before, no problems there. Fatal error: Nesting level too deep - recursive dependency? in Unknown on line 0 Cannot find module (IP-MIB): At line 0 in (none) Cannot find module
1
1586
by: Simon Kittle | last post by:
Hi, Is it possible in PHP to provide a nice pretty page when a fatal error occurs? (Or any of the errors listed here http://uk.php.net/manual/en/function.set-error-handler.php which you cannot catch). I have error_reporting turned off as I have a production server - but that just gives a blank page which is less than good.
2
8101
by: Midgard | last post by:
I have this error: Fatal error: Cannot redeclare send_welcome_mail() (previously declared in /home/oxxowhol/public_html/config.php:21) in /home/oxxowhol/public_html/config.php on line 21 Why?
4
1811
by: Kesavan | last post by:
I need polymorphism in php. When I run this following code I get the following error. Fatal error: Cannot redeclare aClass::aPrint() in C:\Program Files \xampp\htdocs\k7\prCls.php on line 16 How I rectify it? <?php
1
1872
by: srilathaapi | last post by:
Hi All, I am getting the error cannot redeclare the class some xxx in file xxx.php. bcz i m including xxx.php in 3 diffrent functions in the same file to invoke the 3 differnet functions in the xxx.php from 3 different functions.so can u give me the solution. Thanks&regards Sri
2
14327
by: srilathaapi | last post by:
Hi All, I am getting the error cannot redeclare the class some xxx in file xxx.php. bcz i m including xxx.php in 3 diffrent functions in the same file to invoke the 3 differnet functions in the xxx.php from 3 different functions.so can u give me the solution. Thanks&regards Sri
2
1821
by: ann86 | last post by:
Hello, I am a newbie to PHP and I am working on a site that was created by someone else. The server was updated yesterday so now I am getting the error Fatal error: Cannot redeclare date_format(). I know that this is built in with PHP 5 but I need to know how to fix it without getting another error message saying that my cookies are disabled. Can anyone please help me?
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10438
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10214
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10164
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9042
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7540
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.