Skip to content


DCOM-17: Add Collection::slice($offset, $length) #471

doctrinebot opened this Issue · 4 comments

2 participants


Jira issue originally created by user @beberlei:

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 created by @beberlei:

Updated preserve paragraph


Comment created by @beberlei:



Issue was closed with resolution "Fixed"


Comment created by jpieper:

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

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.0.0-RC1 milestone
@doctrinebot doctrinebot closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.