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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to