Object References Problem

From: Date: Thu, 30 Oct 2003 21:54:49 +0000
Subject: Object References Problem
Groups: php.general 
Request: Send a blank email to php-general+get-168186@lists.php.net to get a copy of this message
Hi there, I'm having trouble with passing objects as references. What I want to do is something like this: class object_1 { var $my_chld; var $my_array; function object_1() { $this->my_array = array('id' => 0, 'name'=>''); $this->my_child = new object_2($this); } } class object_2 { var $my_parent; function object_2(&$parent_object) { $this->my_parent = $parent_object; } function set_parent() { $this->my_parent->my_array['id'] = 1; $this-> my_parent->my_array['name'] = 'test'; } } $instance = new object_1(); $instance->my_child->set_parent(); echo "instance: ".$instance->my_array['name']."<br>"; echo "parent: ".$instance->my_child->my_parent->my_array['name']."<br>"; The above code give the output: instance: parent: test where I want it to give: instance: test parent: test but somewhere along the way, the reference to the parent object is being broken. I've looked all over the place, and I can't find the answer to this. Can somebody please help me? Cheers, Gareth

« previous php.general (#168186) next »