public function setItem(int $index, callable $value) { $count = $this->getCount(); if ($index <= $count) { parent::setItem($index, $value); } else { throw new InvalidArgumentException('Adding items only allowed with [] operator.'); } }