* Thus wrote Tom Rogers ([EMAIL PROTECTED]):
> Hi,
> 
> Monday, October 6, 2003, 3:20:08 AM, you 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;
>     .
>     .
>   }
>   .
>   .
> }

On the global topic, I would suggest establishing a standard
naming convention for your common globals that are used, I do
something like:
  $__object_something__;

With your global var I can see myself writing something that will
overwrite that $class_ref, Like say if I'm handling something that
has to do with referee's in school classes :)  Preceeding the
global vars with '__' or something will keep the namespace clashing
cases down to a minimum.


Curt
-- 
List Stats: http://zirzow.dyndns.org/html/mlists/php_general/

"I used to think I was indecisive, but now I'm not so sure."

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

Reply via email to