Page 1 of 1

help: cannot redeclare function

Posted: Wed Nov 03, 2004 5:47 pm
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

Posted: Wed Nov 03, 2004 5:54 pm
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

Posted: Wed Nov 03, 2004 5:59 pm
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    
    }
}
// ........

Posted: Wed Nov 03, 2004 6:01 pm
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".

Posted: Wed Nov 03, 2004 6:09 pm
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

Posted: Wed Nov 03, 2004 6:34 pm
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.

Posted: Wed Nov 03, 2004 7:17 pm
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.