function getRoot() { $r = $this->parent; $n = $r === null ? null : $r->parent; while ($n !== null) { $r = $n; $n = $r->parent; } return $r; }