help: cannot redeclare function

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
mcog_esteban
Forum Contributor
Posts: 127
Joined: Tue Dec 30, 2003 3:28 pm

help: cannot redeclare function

Post by mcog_esteban »

hello.
i'm using php + odbc to retrive data from a bd, i have made a function called "my_odbc_fetch_array()" that works similar as mysql_fetch_array(), this function is in a .inc file.
the problem is that i keep getting "Cannot redeclare my_odbc_fetch_array() (previously declared in conf.inc) in every script that i include conf.inc.
i'm really frustated with this, even more when everything works well at home(i have xampp installed) and when i install the scripts at other place they doesn't work(i get this errors).

thanks
LostMyLove
Forum Newbie
Posts: 20
Joined: Mon Sep 27, 2004 12:20 pm

Post by LostMyLove »

did u don't putting 2 times this function?

or including the file two times...

example:

index.php

Code: Select all

include('*.inc");
include('sub.php');
sub.php

Code: Select all

include('*.inc');
? if yes, is that the problem, let u delete the include os the sub.php ...

and try using include_once() if error persists
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

well, you can wrap your function in if(!function_exists(...)) block:

Code: Select all

//........
if( !function_exists('my_odbc_fetch_array') ) {
    function my_odbc_fetch_array() {
//      function body here    
    }
}
// ........
mcog_esteban
Forum Contributor
Posts: 127
Joined: Tue Dec 30, 2003 3:28 pm

Post by mcog_esteban »

no.
i have the function defined in conf.inc and i get this error in every script that as include "conf.inc".
mcog_esteban
Forum Contributor
Posts: 127
Joined: Tue Dec 30, 2003 3:28 pm

Post by mcog_esteban »

but i don't understand why i don't this problems at home,everything work well.

i have this errors when i run the scripts on other machine
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

like weirdan said, if in these other computers odbc functions exists you can see this problem. you can check with weirdans code and execute the function.
mcog_esteban
Forum Contributor
Posts: 127
Joined: Tue Dec 30, 2003 3:28 pm

Post by mcog_esteban »

ok.
i tried the solution of weirdan, and it's working.i'm not getting this errors any more.

thanks to all.
Post Reply