RE: [PEAR-DEV] MDB 2.x
| From: | Lukas Smith | Date: | Tue, 26 Aug 2003 12:01:29 +0000 |
| Subject: | RE: [PEAR-DEV] MDB 2.x | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-20547@lists.php.net to get a copy of this message | ||
> From: Lukas Smith [mailto:smith@backendmedia.com]
> Sent: Tuesday, August 26, 2003 11:28 AM
> > C) consider loading the connection into the class when you create
it..
> > eg..
> > in loadModule
> > $this->{$module} = new $class;
> > $this->{$module}->db = &$this;
> > reutrn $this->{$module};
> > }
> > that way you dont need to keep passing $db to all the methods....?
>
> well the reason why I did it this way is to prevent resursive
references
>
> $mdb->manager->db would point to $mdb ...
>
> kinda ugly.
>
> For the extended module I also did it to enable static calls
> MDB_Extended::queryAll($db, $sql, ...)
Pondering the issue some more I found a solution.
Since all instances of MDB are stored in a global array anyways to
provide the singleton pattern etc there is another alternative.
In order to prevent recursive references each of the modules could store
the key said global array as a reference to the given MDB instance. This
is a perfect solution for the datatype and manager module. This now
brings up the question if being able to call the extended module
statically is really worth the trouble of having to pass along the
database instance all the time.
I remember that I brought up this question before and people seemed to
like the idea of being able to call those methods statically. However it
seemed to me that it was more of an additional reason and the biggest
issue people wanted to evade was recursive references.
Regards,
Lukas