public function getNonEmptySibling($index, $direction) { while (true) { $index += $direction; if (!$this->offsetExists($index)) { return; } if (!$this[$index]->isEmpty()) { return $index; } } }