[DCOM-17] Add Collection::slice($offset, $length) Created: 08/Aug/10  Updated: 14/Jan/11  Resolved: 24/Aug/10

Status: Resolved
Project: Doctrine Common
Component/s: Collections
Affects Version/s: 2.0.0-BETA4
Fix Version/s: 2.0.0-RC1
Security Level: All

Type: Improvement Priority: Major
Reporter: Benjamin Eberlei Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None


Since we are still at a point were bc breaks are potentially not so harming:

We need a slice() method on the Collection for forward compatibility, the support for large and very large collections using FETCH_EXTRA would heavily benefit from a method like this.

 * Extract a slice of $length elements starting at position $offset from the Collection.
 * If $length is null it returns all elements from $offset to the end of the Collection.
 * Keys have to be preserved by this method.
 * @param int $offset
 * @param int $length
 * @return array
public function slice($offset, $length = null);

The ArrayCollection implement would be:

public function slice($offset, $length = null);
    return array_slice($this->_elements, $offset, $length, true); // preserve keys

Comment by Benjamin Eberlei [ 08/Aug/10 ]

Updated preserve paragraph

Comment by Benjamin Eberlei [ 24/Aug/10 ]


Comment by Jan Pieper [ 14/Jan/11 ]

Is there any reason why slice() returns an array although methods like filter() and map() return an instance of Doctrine\Common\Collections\ArrayCollection?

Generated at Mon Nov 30 13:54:07 EST 2015 using JIRA 6.4.10#64025-sha1:5b8b74079161cd76a20ab66dda52747ee6701bd6.