Re: about referencing A from B You're exactly right - to make a reference, you'll need to either 1) make A global, or 2) pass A as a parameter to B's constructor.
Re: (un)serialising maintaining reference, not copy Sorry, haven't tried serialising an object with references in it before - I guess the easiest way to find out is to do a simple test. Something like (in pseudocode) 1. define classes A and B 2. instantiate A and B 3. serialise A and B 4. unset() objects A and B 5. unserialise A and B 6. change something in A 7. see if changes are shown in B -----Original Message----- From: Alok K. Dhir [mailto:[EMAIL PROTECTED]] Sent: Thursday, April 11, 2002 6:52 AM To: [EMAIL PROTECTED] Subject: [PHP] OO-PHP Style question (sent this to the wrong list the first time - apologies in advance) Given an app with the following overall class structure: Base.class { function Base() { ##initialize stuff } } A.class extends Base { var $var; var $b; function A() { $var="x"; $b=new B.class(); } } B.class extends Base { var $y; function B() { $y="something"; ##How do I refer to $var in A } } Now, how would/could an instance of B get to a variable in A (i.e. the calling class). One (seemingly rather ugly) way is to declare the A instance global and refer to that from within B. I.e. <? global $x $x=new A; ## now we can say something like "$x->var" from within B ?> Or, another way is to pass a reference to A in with the call to B - so we'd change the class defs for A and B to look like: A.class extends Base { var $var; var $b; function A() { $var="x"; $b=new B.class($this); //pass a ref to myself } } B.class extends Base { var $a; var $y; function B(&$a) { //always take this arg as a reference $y="something"; // now $a contains a ref to the calling object echo $a->var; } } Am I thinking about this correctly? Am I missing some obvious language contruct which would obviate the need for A to pass itself as an arg to the instantiation of B? Is my object structure completely naive? In the second case, what happens after you serialize and unserialize an A object as in a session? Will The instance of B called $b in the A object still contain a _reference_ to the A object in it's $a var, or will it now have a _copy_? I'm trying to get an idea of best practices for these types of issues. Any comments/discussion is very much appreciated. Al -- PHP Install Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php