From a62cf000613127735e31e6a4edf1033f19f4e8b7 Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Tue, 19 May 2009 23:11:38 +0000 Subject: [PATCH] BUGFIX #3777 DataObjectSet_Iterator->getOffset() shouldn't die if trying to seek past the set (mobiusnz) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@77270 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/DataObjectSet.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/model/DataObjectSet.php b/core/model/DataObjectSet.php index 6bcde966c..fbafbe745 100644 --- a/core/model/DataObjectSet.php +++ b/core/model/DataObjectSet.php @@ -1105,15 +1105,20 @@ class DataObjectSet_Iterator implements Iterator { /** * Return the object in this set offset by $offset from the iterator pointer. * @param int $offset The offset. - * @return DataObject + * @return DataObject|boolean DataObject of offset item, or boolean FALSE if not found */ public function getOffset($offset) { $keys = array_keys($this->items); foreach($keys as $i => $key) { if($key == key($this->items)) break; } - $requiredKey = $keys[$i + $offset]; - return $this->items [$requiredKey]; + + if(isset($keys[$i + $offset])) { + $requiredKey = $keys[$i + $offset]; + return $this->items[$requiredKey]; + } + + return false; } }