PHPackages                             axonode/collections - 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. axonode/collections

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

axonode/collections
===================

This library provides implementations for common data structures (Pair, List, Dictionary, Set) in PHP.

1.1.1(5mo ago)04gpl-3.0PHPPHP ^8.2CI passing

Since Dec 18Pushed 4mo agoCompare

[ Source](https://github.com/Axonode/collections)[ Packagist](https://packagist.org/packages/axonode/collections)[ RSS](/packages/axonode-collections/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (4)Used By (0)

Axonode Collections
===================

[](#axonode-collections)

Table of contents
-----------------

[](#table-of-contents)

1. [Description](#description)
2. [Requirements](#requirements)
3. [Installation](#installation)
4. [Provided interfaces](#provided-interfaces)
5. [Usage](#usage)
6. [Contributing](#contributing)
7. [License](#license)

Description
-----------

[](#description)

This library provides implementations for common data structures (Pair, List, Dictionary, Set) in PHP.

Requirements
------------

[](#requirements)

- PHP 8.2
- Composer
- SPL extension
- Random extension

Installation
------------

[](#installation)

1. Add the package to your project using Composer: ```
    composer require axonode/collections
    ```

Provided interfaces
-------------------

[](#provided-interfaces)

For mockability, the library defines various interfaces which are implemented by concrete classes.

- `\Axonode\Collections\Object\Hashable` Represents an object that can be uniquely identified by a hash.
- `\Axonode\Collections\Contracts\IPair` Represents an immutable key-value pair.
- `\Axonode\Collections\Contracts\ICollection` Represents a collection of items. Parent to all collection interfaces.
- `\Axonode\Collections\Contracts\IList` Represents a list of items. The items are indexed by sequential integers.
- `\Axonode\Collections\Contracts\IDictionary` Represents a collection of items, where each item is associated with a unique key. The keys may be any of the following types: `string`, `integer`, `float`, `resource`, `object`, `boolean`, `array` or `null`.
- `\Axonode\Collections\Contracts\ISet` Represents a collection of unique items. The items are indexed by sequential integers.

Usage
-----

[](#usage)

### `\Axonode\Collections\Object\Hashable`

[](#axonodecollectionsobjecthashable)

The `Hashable` interface represents an object, which can be uniquely identified by a hash. The hash is a string, which is used to compare objects for equality. If you do not want to customise how the hash is created, this package provides a trait (`\Axonode\Collections\Object\GeneratesObjectHash`), which implements the `getHash` method using the `spl_object_hash`function.

### `\Axonode\Collections\Pair`

[](#axonodecollectionspairtkey-tvalue)

The `Pair` class represents an immutable key-value pair.

To create a new instance use the constructor provide by the class:

```
$pair = new \Axonode\Collections\Pair('key', 'value');
```

Pairs are immutable, so you cannot change the key or value after the object has been created, but for convenience, the interface provides methods to create a new pair with a different key or value:

```
$newPair = $pair->withKey('newKey');
$newPair = $pair->withValue('newValue');
```

### Collections

[](#collections)

All collections are derived from the interface `\Axonode\Collections\Contracts\ICollection`. The base `ICollection` interface extends

- `\Countable` - so you can simply count the number of elements of a collection by passing it to the `count` function
- `\ArrayAccess` - so you can access and set elements of a collection as if it were a traditional array
- `\Iterator` - so you can loop through the collection

---

#### `\Axonode\Collections\ArrayList`

[](#axonodecollectionsarraylistt)

The `ArrayList` (implementing `\Axonode\Collections\Contracts\IList`) class represents a list of items. The items are indexed by sequential integers. To maintain the incrementing sequence of keys in the list, after any operation which mutates the number or order of elements in the list, the keys are reindexed.

You can get a new instance of an `ArrayList` by calling its constructor:

```
$emptyList = new \Axonode\Collections\ArrayList();
$anotherList = new \Axonode\Collections\ArrayList(['item1', 'item2', 'item3']);
```

---

#### `\Axonode\Collections\Dictionary`

[](#axonodecollectionsdictionarytkey-tvalue)

The `Dictionary` (implementing `\Axonode\Collections\Contracts\IDictionary`) class represents a collection of items, where each item is associated with a unique key. The keys usually holds a significant meaning. Unlike a traditional array, the keys may be of any type supported by PHP. To achieve this, a dictionary is a list of `\Axonode\Collections\Contracts\IPair` implementations.

You can get a new instance of a `Dictionary` by calling its constructor:

```
// creating an empty dictionary by passing no arguments to the constructor
$emptyDictionary = new \Axonode\Collections\Dictionary();

$key1 = new stdClass();
$key2 = new stdClass();
// creating a dictionary where keys will be `stdClass` instances
$anotherDictionary = new \Axonode\Collections\Dictionary(
    new \Axonode\Collections\Pair($key1, 'value1'),
    new \Axonode\Collections\Pair($key2, 'value2'),
);

// retrieving a value by key
echo $anotherDictionary[$key1]; // 'value1'
```

---

#### `\Axonode\Collections\Set`

[](#axonodecollectionssett)

The `Set` (implementing `\Axonode\Collections\Contracts\ISet`) class represents a collection of unique items. The items are indexed by sequential integers. To maintain the incrementing sequence of keys in the list, after any operation which mutates the number or order of elements in the list, the keys are reindexed.

You can get a new instance of an `Set` by calling its constructor:

```
$emptySet = new \Axonode\Collections\Set();
$anotherSet = new \Axonode\Collections\ArraySet(['item1', 'item2', 'item2']); // will result in ['item1', 'item2']
```

---

Contributing
------------

[](#contributing)

1. Fork the repository.
2. Create a new branch (`git checkout -b feature-branch`).
3. Commit your changes (`git commit -am 'Add new feature'`).
4. Push to the branch (`git push origin feature-branch`).
5. Create a new Pull Request.

License
-------

[](#license)

This project is licensed under the GPL v3 License - see the `LICENSE` file for details.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance74

Regular maintenance activity

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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.

###  Release Activity

Cadence

Every ~178 days

Total

3

Last Release

160d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3c4191f039694ff652ae282e2043f0b6934c3a9f2eda4ac9dabd76e8635d7167?d=identicon)[namenyij](/maintainers/namenyij)

---

Top Contributors

[![jnamenyi](https://avatars.githubusercontent.com/u/56647220?v=4)](https://github.com/jnamenyi "jnamenyi (14 commits)")

---

Tags

collectionsphpphp-library

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/axonode-collections/health.svg)

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

PHPackages © 2026

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