Object References Problem
From: Gareth Williams (gareth_at_venditor.com)
Date: 10/30/03
- Next message: Allowee: "Re: [PHP] removing all duplicate values from an array"
- Previous message: Chris Hubbard: "RE: [PHP] stat(), file_exists(), is_file() on Windows2000"
- Next in thread: Boyan Nedkov: "Re: [PHP] Object References Problem"
- Reply: Boyan Nedkov: "Re: [PHP] Object References Problem"
- Reply: Michael Sims: "Re: [PHP] Object References Problem"
- Reply: Manuel VáZquez Acosta: "Re: Object References Problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Allowee: "Re: [PHP] removing all duplicate values from an array"
- Previous message: Chris Hubbard: "RE: [PHP] stat(), file_exists(), is_file() on Windows2000"
- Next in thread: Boyan Nedkov: "Re: [PHP] Object References Problem"
- Reply: Boyan Nedkov: "Re: [PHP] Object References Problem"
- Reply: Michael Sims: "Re: [PHP] Object References Problem"
- Reply: Manuel VáZquez Acosta: "Re: Object References Problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|