Globals
| From: | David Schultz | Date: | Sun, 20 Aug 2000 08:01:17 +0000 |
| Subject: | Globals | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-12634@lists.php.net to get a copy of this message | ||
I have some functions which are used in several scripts, so I have them in
includes. However, the functions need at least five global variables each. I
don't want any flames about using global variables--- Apache variables are
global and there's nothing I can do about it, variables relating to the user
authentication include file are global and it would be stupid to do anything
else, and others are so extensively used in the main body of the script that
it would be pointless to commit changes to the database just to have the
functions read them back. Passing them as arguments is also a bit silly
because there are rather a lot of them, and most of them don't change---
those that do are parameters already.
Currently, I simply declare all of the globals at the start of the function,
and my nomenclature is such that there shouldn't be any confusion between
local variables. However, it looks very sloppy. Should I a) rewrite
everything to use the GLOBALS array, b) split each function into one include
file, and just include the file whenever I mean to invoke the "function" or
c) do something else creative that I haven't thought of yet. Are there any
performance reasons that I might choose one over the other? Thanks in
advance.