mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
mlantahler:Bugfix: Added checks in DataObjectSet::First() and DataObjectSet::Last() to prevent errors on an empty $items array. (merged from branches/gsoc)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@41778 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
898d897c9e
commit
d47e6cf67c
@ -526,6 +526,9 @@ class DataObjectSet extends ViewableData implements Iterator {
|
||||
* @return DataObject
|
||||
*/
|
||||
public function First() {
|
||||
if(count($this->items) < 1)
|
||||
return null;
|
||||
|
||||
$keys = array_keys($this->items);
|
||||
return sizeof($keys) > 0 ? $this->items[$keys[0]] : null;
|
||||
}
|
||||
@ -535,6 +538,9 @@ class DataObjectSet extends ViewableData implements Iterator {
|
||||
* @return DataObject
|
||||
*/
|
||||
public function Last() {
|
||||
if(count($this->items) < 1)
|
||||
return null;
|
||||
|
||||
$keys = array_keys($this->items);
|
||||
return $this->items[$keys[sizeof($keys)-1]];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user