|
Posted by Rik on 02/05/07 21:39
Gunnar G <debian@comhem.se> wrote:
> Hi.
> Another question for you guys, you are very helpful.
> If I have the files a.php, b.php, c.php and I must include them, but they
> all contain the same function foo(), is there a way to tell PHP to call
> the
> function foo from a.php, foo from b.php , and so on? Or will the last
> included file replace the previous foo() functions?
>
> Any suggestion on a workaround? Can I call afile.php which inclueds
> a.php
> and runs foo() from a.php?
> Or will I have to rewrite all the files a.php, b.php, etc. ?
A function cannot be redeclared, and this will result in an error. If they
do different things, you should name them different accordingly. You can
however declare functions in mulitple places with a conditional, allthough
it's not advisable (if the function changes you have to make changes all
over). This is done by:
if(!function_exists('foo')){
function foo(){
//etc...
}
}
--
Rik Wasmus
Navigation:
[Reply to this message]
|