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

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

edumarques/typed-collections
============================

Typed collections are an implementation of typed lists.

v2.0.0(2y ago)65.8k↓33.3%1MITPHPPHP &gt;=8.3

Since May 22Pushed 2y ago1 watchersCompare

[ Source](https://github.com/edumarques/typed-collections)[ Packagist](https://packagist.org/packages/edumarques/typed-collections)[ RSS](/packages/edumarques-typed-collections/feed)WikiDiscussions v2.x Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (5)Used By (0)

Typed Collections
=================

[](#typed-collections)

[![Packagist Dependency Version](https://camo.githubusercontent.com/5cd558b31a6708cac4e969b5511782685c416d0ac06fe051738d7c309267dfee/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f6564756d6172717565732f74797065642d636f6c6c656374696f6e732f7068703f76657273696f6e3d76322e782d64657626636f6c6f723d253233373737424233)](https://camo.githubusercontent.com/5cd558b31a6708cac4e969b5511782685c416d0ac06fe051738d7c309267dfee/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f6564756d6172717565732f74797065642d636f6c6c656374696f6e732f7068703f76657273696f6e3d76322e782d64657626636f6c6f723d253233373737424233)[![GitHub](https://camo.githubusercontent.com/586a7bf86d5fb39da3180c73fcb4a7993b8199aae1705e0d548e8906a0c59ccd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6564756d6172717565732f74797065642d636f6c6c656374696f6e73)](https://camo.githubusercontent.com/586a7bf86d5fb39da3180c73fcb4a7993b8199aae1705e0d548e8906a0c59ccd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6564756d6172717565732f74797065642d636f6c6c656374696f6e73)[![edumarques](https://camo.githubusercontent.com/60efc23a88e89cc825df78ee541186f4254bbb99077380c10263ad313c4cbd50/68747470733a2f2f636972636c6563692e636f6d2f67682f6564756d6172717565732f74797065642d636f6c6c656374696f6e732e7376673f7374796c653d736869656c64)](https://app.circleci.com/pipelines/github/edumarques)[![codecov](https://camo.githubusercontent.com/ee0a35673b56ee002cc138db83f76399a7f7851f87ec3c2f5af5c1d03978adf4/68747470733a2f2f636f6465636f762e696f2f67682f6564756d6172717565732f74797065642d636f6c6c656374696f6e732f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d4142474d797672333535)](https://codecov.io/gh/edumarques/typed-collections)

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

[](#description)

Typed collections are an implementation of typed lists. Collections allow us to have traversable lists of a predetermined type and its subtypes. Its behavior prevents the looseness of arrays in PHP.

This library contains four collection classes: mutable and immutable lists, and mutable and immutable dictionaries. Mutable lists/dictionaries have its internal array altered whenever we perform operations on it. Immutable lists/dictionaries generate a new instance of itself when operations are done on it.

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

[](#installation)

```
composer require edumarques/typed-collections:2.*

```

Basic usage
-----------

[](#basic-usage)

```
use EduardoMarques\TypedCollections\TypedCollection;
use EduardoMarques\TypedCollections\TypedCollectionImmutable;
use EduardoMarques\TypedCollections\Enum\ScalarType;
use EduardoMarques\TypedCollections\Enum\NonScalarType;

$typedCollection1 = TypedCollection::create(ScalarType::INTEGER);
$typedCollection2 = TypedCollection::create(ScalarType::STRING);

$typedCollectionImmutable1 = TypedCollectionImmutable::create(NonScalarType::CALLABLE);
$typedCollectionImmutable2 = TypedCollectionImmutable::create(\stdClass::class);
```

```
use EduardoMarques\TypedCollections\TypedDictionary;
use EduardoMarques\TypedCollections\TypedDictionaryImmutable;
use EduardoMarques\TypedCollections\Enum\ScalarType;
use EduardoMarques\TypedCollections\Enum\NonScalarType;

$typedDictionary1 = TypedDictionary::create(ScalarType::INTEGER, ScalarType::STRING);
$typedDictionary2 = TypedDictionary::create(ScalarType::STRING, ScalarType::DOUBLE);

$typedDictionaryImmutable1 = TypedDictionaryImmutable::create(ScalarType::INTEGER, NonScalarType::CALLABLE);
$typedDictionaryImmutable2 = TypedDictionaryImmutable::create(ScalarType::STRING, \stdClass::class);
```

Collection
----------

[](#collection)

A PHP implementation of an array list. Its type is specified at instantiation/construction. The class will perform runtime type checks to validate the appropriate values are being added. Many of the standard array functionalities are encapsulated in this class.

Dictionary
----------

[](#dictionary)

Dictionaries extend Collections' functionalities. The main difference is that they work with associative arrays, where you map keys to values.

Supported types:
----------------

[](#supported-types)

- `ScalarType::INTEGER`
- `ScalarType::STRING`
- `ScalarType::BOOLEAN`
- `ScalarType::DOUBLE`
- `NonScalarType::ARRAY`
- `NonScalarType::CALLABLE`
- `class-string`

Support for abstract classes and interfaces
-------------------------------------------

[](#support-for-abstract-classes-and-interfaces)

Collections and Dictionaries will check inheritance, so if you require a base class, derived classes can be added safely.

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

[](#contributing)

Contributors are always welcome! For more information on how you can contribute, please read our [contribution guideline](CONTRIBUTING.md).

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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 ~59 days

Total

5

Last Release

855d ago

Major Versions

v1.1.0 → v2.0.02024-01-14

PHP version history (2 changes)v1.0.0PHP &gt;=7.1

v2.0.0PHP &gt;=8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7669915?v=4)[Eduardo Marques](/maintainers/edumarques)[@edumarques](https://github.com/edumarques)

---

Top Contributors

[![edumarques](https://avatars.githubusercontent.com/u/7669915?v=4)](https://github.com/edumarques "edumarques (1 commits)")

---

Tags

collectionsphptype-safe

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

PHPackages © 2026

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