PHPackages                             idimsh/collection - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. idimsh/collection

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

idimsh/collection
=================

A generic objects/variables holder and iterator

181PHPCI failing

Since Aug 30Pushed 5y ago1 watchersCompare

[ Source](https://github.com/idimsh/collection)[ Packagist](https://packagist.org/packages/idimsh/collection)[ RSS](/packages/idimsh-collection/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![Build Status](https://camo.githubusercontent.com/3eca21e59a9a2c3885227c636ef1ca744f308065d0028e155099c6d5c215f75d/68747470733a2f2f7472617669732d63692e6f72672f6964696d73682f636f6c6c656374696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/idimsh/collection)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/aaffd610ab7d91f470f452c218d46ab2aeb76168d13ac99760b6a853e7ec812e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6964696d73682f636f6c6c656374696f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/idimsh/collection/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/07ebbc87a21d37eb777be077d33d81128b4e80327781c8a1b4058ed052cd5fcb/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6964696d73682f636f6c6c656374696f6e2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/idimsh/collection/?branch=master)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

Collection: A Generic PHP Objects/Variables Holder and Iterator
===============================================================

[](#collection-a-generic-php-objectsvariables-holder-and-iterator)

A library to store variables in an iterator, support some operations like sorting and swapping elements.

### Requirements

[](#requirements)

- PHP &gt;= 5.6

### Installation

[](#installation)

```
$ composer require idimsh/collection
```

in `composer.json`:

```
"require": {
  "idimsh/collection": "dev-master"
}

```

### Usage

[](#usage)

The class `\Dimsh\Models\Collections\Collection` is meant to be extended by your implementation of the *list* you want to create, extending the class will provide type hints for autocomplete and it is not a must.
like:

```
use Dimsh\Models\Collections;

/**
 * Class DefinitionsList
 *
 * @method \Definition offsetGet();
 * @method \Definition current()
 * @method \Definition last()
 * @method \Definition first()
 *
 */
class DefinitionsList extends Collection {
    /**
     * @param \Definition $value
     *
     * @throws \Exception
     */
    protected function preAdd($value) {
        if (! $value instanceof \Definition) {
            throw new \Exception("DefinitionsList can accept items of type Definition only");
        }
    }
}

$list = new \DefinitionsList;
$list[] = new \Definition;
$list['string-index'] = new \Definition;
$list->add(new \Definition);

// Looping
for ($list->rewind(); $list->valid(); $list->next()) {
    $definition = $list->current();
    $index = $list->key();
}
```

### Useful Methods:

[](#useful-methods)

```
/**
 * @var \Dimsh\Models\Collections\Collection $list
 * @var \Dimsh\Models\Collections\Collection $another_list
 */

$list->first(); // Get the first item
$list->last(); // Get the last

$list->swap($offset1, $offset2); // swap items
$list->diffKey($another_list); // Get array diff by keys (offsets)
$list->intersectKey($another_list); // get array_intersect_key using offsets.
```

### Why

[](#why)

To find a way to store objects inside an array-like object in order for the collection to be passable by reference, storing objects in PHP Arrays will not provide this feature.

### License

[](#license)

MIT

#### Alternatives

[](#alternatives)

`\SplObjectStorage` Provides a way to store objects, this package adds the array functions to the collection of objects.

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity32

Early-stage or recently created project

 Bus Factor1

Top contributor holds 77.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/6051f256445126a33260284644052c0eafa146bb2877bdd46522a280676e3ccd?d=identicon)[idimsh](/maintainers/idimsh)

---

Top Contributors

[![idimsh](https://avatars.githubusercontent.com/u/5890777?v=4)](https://github.com/idimsh "idimsh (14 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (4 commits)")

### Embed Badge

![Health badge](/badges/idimsh-collection/health.svg)

```
[![Health](https://phpackages.com/badges/idimsh-collection/health.svg)](https://phpackages.com/packages/idimsh-collection)
```

###  Alternatives

[doublesecretagency/craft-upvote

Lets your users upvote/downvote, "like", or favorite any type of element.

1634.6k](/packages/doublesecretagency-craft-upvote)[usamamuneerchaudhary/country-city-state

Country City State Data Provider for Laravel 12+

242.6k](/packages/usamamuneerchaudhary-country-city-state)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
