user functions

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-04-2004
Reimar Bauer
 
Posts: n/a
Default user functions

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

Reply With Quote
  #2 (permalink)  
Old 05-04-2004
Garp
 
Posts: n/a
Default Re: user functions


"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


Reply With Quote
  #3 (permalink)  
Old 05-04-2004
Pedro Graca
 
Posts: n/a
Default Re: user functions

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 :
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 08:42 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0