Object References Problem

From: Gareth Williams (gareth_at_venditor.com)
Date: 10/30/03


Date: Thu, 30 Oct 2003 22:54:49 +0100
To: php-general@lists.php.net

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



Relevant Pages

  • Re: [PHP] Object References Problem
    ... >I'm having trouble with passing objects as references. ... >parent: test ... mysterious ways that they work in regards to PHP objects, ...
    (php.general)
  • finding class parent information
    ... I can get all of the compponets in a class, and get references to ... JLabel called myLabel belongs to parent JPanel called myPanel ... JButton called myButton belongs to parent JPanel called myPanel ...
    (comp.lang.java.programmer)
  • clutching on to my final attributes...
    ... When I deserialize my Parent object my 2 references to my 'A' object will ... private final Child c; ... void update{ ...
    (comp.lang.java.programmer)
  • Re: Duplicate server entries for the same site code
    ... I think so - if the child site is no longer referenced at the parent. ... >> run PREINST /DELSITE to clean up references to the site if any>> ... >>> Neither log on the parent server reports any entries for either server. ...
    (microsoft.public.sms.setup)
  • Re: TMJ re-revisited
    ... (Newsgroup threading is done based on the References: and Message-ID: ... change off as a new thread, but with a link to the parent post in the ...
    (rec.games.roguelike.angband)