At 21:49 10.11.2002, Mathieu Dumoulin said:
>Hi, i got this project i'm building right now. It basically a core system to
>do adminsitrative modules for web sites.
>I got tons of classes that get created on call of a function like
>sql_setup(), frm_setup(). These functions create the objects from the
>classes so they can be used later in other objects...yada yada yada...
>Now my thing is, instead of always starting my method of an object with
>"global sql_server;" and "global frm_builder", is there a way that these
>variables are declared as global automatically, just like i would get
>$_GET, $_POST and so on, they are already global. I want to do this to
>simplify development since this project is going to be HUGE. And also it
>will facilitate debugging as i've been using "global" at a lot of places and
>when you forget one, PHP assumes the creation of a dummy variable messing up
to begin with, if this project is HUGE as you said, try to avoid globals as
good as you can - they're absolze poison for the readability, stability,
and scalability of any application that extends a single source file with a
couple of lines. Of course this is only MHO, I'm sure others will chime in
I am currently working on an application core that's expected to work with
a nice number of objects, and it is not feasible here to have objects a)
global and simply not possible to have every part of the application using
its own reference to the object instance.
What I did is to create a container for objects and wrap it into a class I
call CCache. As soon as an object gets instantiated it registers itself
with the cache (being uniquely identified by Type and ID). Any part of the
application simply calls the systemwide cache object with type and ID to
retrieve a reference to the specific object it needs just now.
I did a performance profiling on this system, and retrieving an object
reference from the cache needs approx. 0.001 msec.
Just to tell you, not even the cache object is global - there is a public
wrapper function around it to return a reference to the global cache
object. Currently we have approx. 85,000 lines of code, and absolutely no
global variable of our own...
>O Ernest E. Vogelsinger
(\) ICQ #13394035
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php