Re: OO parent/child relationship

From: Date: Mon, 06 Oct 2003 04:48:22 +0000
Subject: Re: OO parent/child relationship
References: 1 2 3 4 5 6  Groups: php.general 
Request: Send a blank email to php-general+get-165134@lists.php.net to get a copy of this message
* Thus wrote Tom Rogers (trogers@kwikin.com): > 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."

« previous php.general (#165134) next »