Algernon83
Programmer
Short version: Why does setting $myobject->myattribute = &$this from inside of another object's constructor pass a copy of $this? How can I pass $this by reference?
Long version:
The source in question can be found at
I have a class called CollapsibleCategory that encapsulates a <div> and an image that, when clicked, makes it appear and disappear. To make this happen, it includes a little delegate that I call an ElementHider. The ElementHider takes in an element to show or hide and one to be clicked to show or hide it. This is arranged in the CollapsibleCategory's constructor, like so:
$this->Hider->InterfaceElement = &$this->Interface;
$this->Hider->HiddenElement = &$this;
So the ElementHider ($this->Hider) should get the ID attribute of $this->Interface and $this when rendering in order to display its JavaScript, but it only works for $this->Interface.
After the CollapsibleCategory is constructed and makes its ElementHider, I call SetID on the CollapsibleCategory, which changes the ID of its interface element. This is rendered properly from the ElementHider, but it does not recognize that the ID of the CollapsibleCategory has changed. If I repeat:
$this->Hider->HiddenElement = &$this;
After changing $this->id, however, it renders properly. Clearly, it's passing by copy. Why?
Long version:
The source in question can be found at
I have a class called CollapsibleCategory that encapsulates a <div> and an image that, when clicked, makes it appear and disappear. To make this happen, it includes a little delegate that I call an ElementHider. The ElementHider takes in an element to show or hide and one to be clicked to show or hide it. This is arranged in the CollapsibleCategory's constructor, like so:
$this->Hider->InterfaceElement = &$this->Interface;
$this->Hider->HiddenElement = &$this;
So the ElementHider ($this->Hider) should get the ID attribute of $this->Interface and $this when rendering in order to display its JavaScript, but it only works for $this->Interface.
After the CollapsibleCategory is constructed and makes its ElementHider, I call SetID on the CollapsibleCategory, which changes the ID of its interface element. This is rendered properly from the ElementHider, but it does not recognize that the ID of the CollapsibleCategory has changed. If I repeat:
$this->Hider->HiddenElement = &$this;
After changing $this->id, however, it renders properly. Clearly, it's passing by copy. Why?