I do it a little differently. Usually I have a global application object (application). Inside this object, I do some basic initialization, for example, creating db objects, caching objects, etc.
I also have a global function that returns an App object .... this way (the definition of the application object is not shown):
define('APPLICATION_ID', 'myApplication'); ${APPLICATION_ID} = new App; function app() { return $GLOBALS[APPLICATION_ID]; }
So, I can use something like the following in any code to refer to objects inside a global object:
app()->db->read($statement); app()->cache->get($cacheKey); app()->debug->set($message); app()->user->getInfo();
This is not ideal, but I believe that this facilitates the situation in many circumstances.
conceptDawg
source share