This is a discussion on user functions within the PHP Language forums, part of the PHP Programming Forums category; I am a bit confused by writing or using my user functions. The only way I know at the moment ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I am a bit confused by writing or using my user functions.
The only way I know at the moment to call my own functions is to put them in one file with the main program. this example comes from http://de.php.net/manual/de/functions.php <?php function foo($foo, $bar = "bar") { echo $foo.$bar; } echo foo("foo"); //gives: foobar echo foo("foo","bar2"); //gives foobar2 ?> I would prefer one file one function. How could I do this or is this absolutly wrong to do it this way. How did php know where to look for a user function. regards Reimar -- Forschungszentrum Juelich email: R.Bauer@fz-juelich.de http://www.fz-juelich.de/icg/icg-i/ ================================================== ================ a IDL library at ForschungsZentrum Juelich http://www.fz-juelich.de/icg/icg-i/i...lib_intro.html |
|
|||
|
"Reimar Bauer" <R.Bauer@fz-juelich.de> wrote in message news:c76gmp$9m5c$1@zam602.zam.kfa-juelich.de... > I am a bit confused by writing or using my user functions. > > The only way I know at the moment to call my own functions is to put them in > one file with the main program. > > this example comes from http://de.php.net/manual/de/functions.php > <?php > > function foo($foo, $bar = "bar") > { > echo $foo.$bar; > } > > echo foo("foo"); > //gives: foobar > > echo foo("foo","bar2"); > //gives foobar2 > > ?> > > I would prefer one file one function. How could I do this or is this > absolutly wrong to do it this way. How did php know where to look for a > user function. Go look up include(), require() etc. Garp |
|
|||
|
Reimar Bauer wrote:
> I am a bit confused by writing or using my user functions. > > The only way I know at the moment to call my own functions is to put them in > one file with the main program. > > this example comes from http://de.php.net/manual/de/functions.php > <?php > > function foo($foo, $bar = "bar") > { > echo $foo.$bar; > } > > echo foo("foo"); > //gives: foobar > > echo foo("foo","bar2"); > //gives foobar2 > > ?> > > I would prefer one file one function. How could I do this or is this > absolutly wrong to do it this way. How did php know where to look for a > user function. I usually put my functions in a separate file which I include. <?php // foo-function.inc.php function foo($foo, $bar = 'bar') { echo $foo, $bar; } ?> Then I include this file in my scripts. For instance, index.php could be <?php // index.php require_once 'foo-function.inc.php'; echo foo('foo'); // gives foobar echo foo('foo', 'bar2'); // fives foobar2 ?> -- USENET would be a better place if everybody read: : mail address : http://www.catb.org/~esr/faqs/smart-questions.html : is valid for : http://www.netmeister.org/news/learn2quote2.html : "text/plain" : http://www.expita.com/nomime.html : to 10K bytes : |