Re: OO parent/child relationship
| From: | Gerard Samuel | Date: | Sun, 05 Oct 2003 22:57:37 +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-165109@lists.php.net to get a copy of this message | ||
Jeremy Johnstone wrote:
What I would do is pass the handles to the objects in the class constructor by reference. For example create one db object similar to this: class database { ... } $db = new database(); and then pass the reference to all other classes like this: class smarty { var $db; function smarty(&$db) {And this is what Im trying to get away from. In addition to passing smarty the $db object by reference, Im going to be passing the user management object to smarty by reference, which in turn has a copied reference to the $db object. So in the end the smarty object is going to have 2 references to the $db object. That is what I want to get away from... $smarty <- $db (by reference) $smarty <- $user_management (by reference) <- $db (by reference)$this->db = &$db;} } This way you don't have the wasted memory of duplicate class instances. Of course PHP5 will make this easier as it passes objects by reference by default. This is currently how Im doing things.