(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