Skip to content

Commit d1352b5

Browse files
committed
Added a handling for non-existing indexes: Seeks to -1, and therefore returns FALSE.
1 parent ea68a28 commit d1352b5

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/PEAR2/Net/RouterOS/ResponseCollection.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ public function rewind()
276276
*
277277
* @param int|string $position The position to move to. If the collection is
278278
* indexed, you can also supply a value to move the pointer to.
279+
* A non-existent index will move the pointer to "-1".
279280
*
280281
* @return Response The {@link Response} at the specified position, or FALSE
281282
* if the specified position is not valid.
@@ -284,7 +285,9 @@ public function seek($position)
284285
{
285286
$this->position = is_int($position)
286287
? $position
287-
: $this->responsesIndex[$this->index][$position];
288+
: ($this->offsetExists($position)
289+
? $this->responsesIndex[$this->index][$position]
290+
: -1);
288291
return $this->current();
289292
}
290293

0 commit comments

Comments
 (0)