/** * Automatically detaches child elements if they belong to this element * * @param string The offset */ public function offsetUnset($offset) { $detach = NULL; if (parent::offsetExists($offset)) { $child = parent::offsetGet($offset); if ($child instanceof Element && $child->__parent === $this) { $detach = $child; } } parent::offsetUnset($offset); if ($detach) { $detach->detach(); } }