Tom Rogers wrote:

To do this I have my classes register themselves in a global array.
For example a mysql class which gets used a lot does this in its constructor:

function mysql_class($db='',$ini=''){
 global $class_ref;
 $class_ref["mysql_class"] =& $this;
 .
 .
 .
}
Then any class that needs access to mysql_class does this in the constructor:
class  galleryClass(
 var $mysql;
 var $db = 'test';
 function galleryClass(){
   global $class_ref;
   if(!empty($class_ref['mysql_class'])):
     $this->mysql =& $class_ref['mysql_class'];
   else:
     $this->mysql = new mysql_class();
   endif;
   if(!empty($this->mysql)):
     $this->con = $this->mysql->get_handle($this->db);
   endif;
   .
   .
 }
 .
 .
}
This way there is only need for 1 instance of the mysql class.
I use global as a bad habit, but you can do the same with $GLOBALS['class_ref']

:)
I asked about something similar to your suggetion the other day ->
http://marc.theaimsgroup.com/?l=php-general&m=106519101018470&w=2

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to