public function offsetSet($index, $newval) { if (!$newval instanceof Task) { throw new \InvalidArgumentException("TaskQueue expects instance of Task only"); } parent::offsetSet($index, $newval); }