If you want access to error functions within the db class it must either extend the error class or have an error object within it. Either ...
Class DB extends Error { ... } Class Core extends DB { ... } or Class DB { var $error; ... function DB() // constructor { ... $this->error = new Error(); } ... } Class Core { var $db; var error; function Core() // constructor { ... $this->db = new DB(); $this->error = new Error(); ... } } at the end of the day, both these are ways of getting around the lack of multiple inheritance Tim Ward ---------- From: [EMAIL PROTECTED] [SMTP:[EMAIL PROTECTED]] Sent: 24 October 2001 22:45 To: [EMAIL PROTECTED] Subject: PHP object communication Not coming from a programming background, I'm going to have difficulty explaining this one... :) I would like to handle an entire application through one object, which in turn contains objects. I only recently "got" classes though, and I don't fully understand if what I want to do is possible, or if I'm going about it the wrong way. Consider: <?php // All of these will be in separate files. // The first two are separated simply because // I want to keep my include files small. class Config { // Base config class. // Just contains data. } class Core extends Config { // Base application class. // Just contains methods. } class Error { // Error handler. } class DB { // Database handler. } ?> Tying the first two together is no problem, I can just extend the Config class. However I would like to incorporate the third and fourth as objects inside the main object: <? // In fact these would be instantiated (is that the // right word?) inside the Core class. $Core = new Core; $Core->Error = new Error; $Core->DB = new DB ?> This is fine when working in the main application, or in the $Core object, but where I get stuck is with communication between the $Core->Error and $Core->DB objects. Say for example that within the DB class I encountered an error, and wanted to talk to the Error object - I /could/ do this: <? class DB { var $Error; function DB() { global $Core; $this->Error = $Core->Error; } } ?> But if I extend the application later and add a bunch of new classes, it means I have to do the same for each object I add. I get the impression that I might be able to do this with references, but I can't get a handle on them for the life of me. Can someone explain? Sorry for the lengthy post. Thanks, adam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]