Page 1 of 1

redeclare?

Posted: Thu Jun 06, 2002 1:39 am
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

Posted: Thu Jun 06, 2002 1:45 am
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

Posted: Thu Jun 06, 2002 1:56 am
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 ;)

Posted: Thu Jun 06, 2002 2:01 am
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

yay

Posted: Thu Jun 06, 2002 2:10 pm
by teksys
okay, thanks a bunh...i'll try it out...i bet it'll work :)

you guys are just great.

it worked

Posted: Thu Jun 06, 2002 2:16 pm
by teksys
it worked! thanks alot guys.