public function remove($index = null) { if ($index !== null) { if (!$this->offsetExists($index)) { throw new \OutOfRangeException('Unknown index: ' . $index); } unset($this->container[$index]); } else { $this->container = array(); } }