So I have a PHP stack that looks roughly like this
Class Stack {
public $name;
public $parent;
public $children = array();
public function __construct($name, $parent = false) {
$this->name = $name;
$this->parent = $parent;
}
public function newChild($name) {
$this->children[] = new Stack($name, $this);
}
public function &top() {
if(is_object($this->parent))
return $this->parent->top();
return $this;
}
}
So somewhere around level 5 of this stack I want to access level 0 using the top() method because i need to make a modification to it. So I do but the modification i make doesnt apply in the final build sequence because it wasent passed by reference. I have tried a couple different ideas but I still am not able to get it to pass thru right. Any ideas?
EDIT: I actually figured it out. What I wrote above actually works perfectly the stack I was working with kinda got huge and somewhere along the way the parent wasent set, so it wasn’t going up the stack all the way. To see what project this actually is. take a peek at http://github.com/EvolutionSDK/lhtml (Logical HTML… gives limited access to PHP from an HTML based page. Basically both the C and V in MVC architecture frameworks.)
Basically in my large PHP Stack I had a unset “parent” variable. Which kept the top() function from accessing the top of the stack. So it only went part way up.
When I figured that out and reconnected the child to its parent and it worked perfectly. As classes are always passed by reference.
Sorry for how long it took me to post this.