You are here: Re: include files with similar contents « PHP Programming Language « IT news, forums, messages
Re: include files with similar contents

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация