redeclare?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
teksys
Forum Commoner
Posts: 34
Joined: Tue May 14, 2002 6:58 pm
Location: Denmark

redeclare?

Post by teksys »

What am i doing wrong when i get this error? I just added my global.inc file to news.php (so i dont have to have two global file, when i can actually use one and the same) but then i get this:

Fatal error: Cannot redeclare db_connect() (previously declared in C:\www\Apache\htdocs\inc\functions.lib.php:24) in C:\www\Apache\htdocs\inc\functions.lib.php on line 21
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

It looks like you declare a function called db_connect() twice in the functions.lib.php file.

So you have two lines that look something like this,

Code: Select all

function db_connect($some_vars) {
Mac
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

this also happens if a function is included (include/require) twice.
if your script includes 'functions.lib.php' and global.inc does the same......
you may prevent this by something like this

Code: Select all

if(!declared('functions.lib.php-included')) { define('functions.lib.php-included');
...<functions.lib.php code > ...
&#125;
EDIT: ok, include_once is better - didn't know this exits ;)
Last edited by volka on Thu Jun 06, 2002 2:02 am, edited 2 times in total.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

If you are including the same file in a number of different locations and thus accidentally reincluding the file try using include_once so that if the code from the file has already been included it won't be again.

Mac
User avatar
teksys
Forum Commoner
Posts: 34
Joined: Tue May 14, 2002 6:58 pm
Location: Denmark

yay

Post by teksys »

okay, thanks a bunh...i'll try it out...i bet it'll work :)

you guys are just great.
User avatar
teksys
Forum Commoner
Posts: 34
Joined: Tue May 14, 2002 6:58 pm
Location: Denmark

it worked

Post by teksys »

it worked! thanks alot guys.
Post Reply