*/
public function map(callable $callback): BaseCollection
{
- return new self(array_map($callback, $this->getArrayCopy()), $this->getTotalCount());
+ $class = get_class($this);
+
+ return new $class(array_map($callback, $this->getArrayCopy()), $this->getTotalCount());
}
/**
*/
public function filter(callable $callback = null, int $flag = 0): BaseCollection
{
- return new self(array_filter($this->getArrayCopy(), $callback, $flag));
+ $class = get_class($this);
+
+ return new $class(array_filter($this->getArrayCopy(), $callback, $flag));
}
/**
*/
public function reverse(): BaseCollection
{
- return new self(array_reverse($this->getArrayCopy()), $this->getTotalCount());
+ $class = get_class($this);
+
+ return new $class(array_reverse($this->getArrayCopy()), $this->getTotalCount());
}
/**
* Split the collection in smaller collections no bigger than the provided length
*
* @param int $length
- * @return self[]
+ * @return static[]
*/
public function chunk(int $length): array
{
}
return array_map(function ($array) {
- return new self($array);
+ $class = get_class($this);
+
+ return new $class($array);
}, array_chunk($this->getArrayCopy(), $length));
}