Re: PHP object communication

From: Date: Wed, 24 Oct 2001 21:50:17 +0000
Subject: Re: PHP object communication
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-72174@lists.php.net to get a copy of this message
On Mié 24 Oct 2001 18:45, you wrote: [snip] > > 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? I think you have things mistaken. What you want is to EXTEND an existing object with new variables and functions. See class CLASS_NAME EXTENDS OLD_CLASS. This is inheritence, a very good thing that OOP has. It means that the new clase will have all the properties that OLD_CLASS had, plus the new ones you add to it. > Sorry for the lengthy post. No problem, that's what snip is for. ;-) -- Porqué usar una base de datos relacional cualquiera, si podés usar PostgreSQL? ----------------------------------------------------------------- Martín Marqués | mmarques@unl.edu.ar Programador, Administrador, DBA | Centro de Telematica Universidad Nacional del Litoral -----------------------------------------------------------------

« previous php.general (#72174) next »