/** * Replace child with another node * @param string|epQueryNode &$key_or_node * @param epQueryNode &$node * @return boolean */ public function replaceChild(&$key_or_node, epQueryNode &$node) { // a key (string) if (is_string($key_or_node)) { if (!isset($this->children[$key_or_node])) { return false; } // remove parent from child $this->children[$key_or_node]->setParent(false); // replace child with new node $this->children[$key_or_node] =& $node; // set parent to child node $node->setParent($this); return true; } else { if ($key_or_node instanceof epQueryNode) { // need to go through all children foreach ($this->children as $key => &$child) { // same as this child (notice ===) if ($child === $key_or_node) { // remove parent from child $this->children[$key]->setParent(false); // replace child with new node $this->children[$key] =& $node; // set parent to child node $node->setParent($this); return true; } } } } return false; }