Chris, thanks for describing your method. The reason I really dislike
Functions in PHP is because you have to pass every variable needed by a
function, even if that variable is global in the main script, which is a
pain in the ass when a function needs a long string of variables. It makes
it easier to forget a variable in the list and can make the code look messy.

So, that's why I prefer includes, because the code is operating on the same
level as the main script and can easily use variables set locally without
making them global.

I'll use a function if it only needs one or two variables passed to it, but,
I find myself using more Includes than Functions because of the variable
passing necessary. 


> From: [EMAIL PROTECTED] (Chris Crane)
> Organization:
> Reply-To: "Chris Crane" <[EMAIL PROTECTED]>
> Newsgroups: php.general
> Date: Wed, 17 Jul 2002 17:05:59 -0400
> Subject: Re: Includes vs. Functions
> I am not sure about efficiency, myself and I often ask this without much if
> anything at all for a response. However, I am the opposite of you, in that I
> prefer to create a library file containing all the functions. To make
> developing the page in something like Dreamweaver or Frontpage easier, I
> global all the variables of a given function, like say Function
> StockQuote($sym) { }. They I include the library file in my PHP
> webpage.Something like this...
> <html>
> <head>
> ~blah
> </head>
> <body>
> <?PHP include("filepath/filename"); StockQuote($sym); ?>
> various html
> ~blah
> ~blah
> <?PHP print $Stock_LastPrice; ?>
> ~blah
> ~blah
> </body>
> </html>
> In the library file, I global the variables;
> function StockQuote($sym) {
> global $Stock_LastPrice, $Stock_Position;
> get the data...
> do something with the data...
> $Stock_LastPrice = This minus that blah blah;
> }
> I can use this variable anywhere I would like and it is very WYSIWYG
> friendly.
> I am not sure how efficient it is though as I mentioned above.

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to