PHPackages                             lc5/typed-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. lc5/typed-collection

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

lc5/typed-collection
====================

Create strictly typed collections in PHP

2.0.0(4y ago)419.7k↓83.3%MITPHPPHP &gt;=7.4.0CI failing

Since Aug 1Pushed 4y ago1 watchersCompare

[ Source](https://github.com/Lc5/TypedCollection)[ Packagist](https://packagist.org/packages/lc5/typed-collection)[ Docs](https://github.com/Lc5/TypedCollection)[ RSS](/packages/lc5-typed-collection/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (4)Versions (4)Used By (0)

TypedCollection
===============

[](#typedcollection)

[![Build Status](https://github.com/Lc5/TypedCollection/workflows/Build/badge.svg)](https://github.com/Lc5/TypedCollection/actions)[![Latest Stable Version](https://camo.githubusercontent.com/e3771664d4792ee10dfde209c5fe368a260585a3e0e417959e15a8009d2b1607/687474703a2f2f706f7365722e707567782e6f72672f6c63352f74797065642d636f6c6c656374696f6e2f76)](https://packagist.org/packages/lc5/typed-collection)[![Total Downloads](https://camo.githubusercontent.com/49af78b8aa85b43c0e3dd48c0f6bd59b98f31d31263081e321efd81c4dd3e1eb/687474703a2f2f706f7365722e707567782e6f72672f6c63352f74797065642d636f6c6c656374696f6e2f646f776e6c6f616473)](https://packagist.org/packages/lc5/typed-collection)[![PHP Version Require](https://camo.githubusercontent.com/98292c0f32c8191823c62d070dc63a035c1b9947883f0896a9c69a39c0233e5e/687474703a2f2f706f7365722e707567782e6f72672f6c63352f74797065642d636f6c6c656374696f6e2f726571756972652f706870)](https://packagist.org/packages/lc5/typed-collection)[![License](https://camo.githubusercontent.com/2f63f91c083f563631f3ccea43d5bf9be41725b522e37d400697820f4177843d/687474703a2f2f706f7365722e707567782e6f72672f6c63352f74797065642d636f6c6c656374696f6e2f6c6963656e7365)](https://packagist.org/packages/lc5/typed-collection)[![PHPStan Enabled](https://camo.githubusercontent.com/441b5874ce4df0a2defc892979c96c46889b69cb32119d04f0b48626349f8bc9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d656e61626c65642d627269676874677265656e2e7376673f7374796c653d666c6174)](https://phpstan.org/)

Create strictly typed collections in PHP.

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

[](#installation)

```
$ composer require lc5/typed-collection

```

AbstractTypedCollection:
------------------------

[](#abstracttypedcollection)

An abstract class used to create strictly typed collections implemented as a type-checking wrapper around `ArrayObject`. The type of elements in a collection is defined by extending `AbstractTypedCollection` and implementing abstract `AbstractTypedCollection::getType` method. It should return the type as a string, which can be any class name or one of the internal types in a form recognised by the internal [gettype()](http://php.net/manual/en/function.gettype.php) function (`"boolean", "integer", "double", "string", "array", "object", "resource", "NULL"`). `UnexpectedValueException`will be thrown, when trying to add an element with an invalid type.

### Usage:

[](#usage)

```
use Lc5\TypedCollection\AbstractTypedCollection;
use Lc5\TypedCollection\Exception\UnexpectedValueException;

class stdClassCollection extends AbstractTypedCollection
{
    public function getType(): string
    {
        return \stdClass::class; //can be any class or internal type
    }
}

$collection = new stdClassCollection([new \stdClass(), new \stdClass()]);
$collection[] = new \stdClass();

try {
    $collection[] = 'invalid';
} catch (UnexpectedValueException $e) {
    echo $e->getMessage(); //Invalid value type: string. Only \stdClass is allowed.
}

try {
    $collection = new stdClassCollection(['invalid', new \stdClass()]);
} catch (UnexpectedValueException $e) {
    echo $e->getMessage(); //Invalid value type: string. Only \stdClass is allowed.
}
```

TypedCollection:
----------------

[](#typedcollection-1)

A strictly typed collection based on ArrayObject. The type of elements in collection is defined using constructor argument, which can be any class name or one of the internal types in a form recognised by internal [gettype()](http://php.net/manual/en/function.gettype.php) function (`"boolean", "integer", "double", "string", "array", "object", "resource", "NULL"`). `UnexpectedValueException` will be thrown, when trying to add element with invalid type.

### Usage:

[](#usage-1)

```
use Lc5\TypedCollection\TypedArray;
use Lc5\TypedCollection\Exception\UnexpectedValueException;

$values = [new \stdClass(), new \stdClass()];

$typedCollection = new TypedCollection(\stdClass::class, $values);
$typedCollection[] = new \stdClass();

try {
    $typedCollection[] = 'invalid';
} catch (UnexpectedValueException $e) {
    echo $e->getMessage(); //Invalid value type: string. Only \stdClass is allowed.
}
```

The behavior is identical as in `AbstractTypedCollection`.

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity65

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

Total

3

Last Release

1667d ago

Major Versions

1.0.1 → 2.0.02021-12-09

PHP version history (2 changes)1.0.0PHP &gt;=5.6.0

2.0.0PHP &gt;=7.4.0

### Community

Maintainers

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

---

Top Contributors

[![Lc5](https://avatars.githubusercontent.com/u/3340775?v=4)](https://github.com/Lc5 "Lc5 (39 commits)")

---

Tags

collectiontyped-collection

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StyleECS

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[phpcollection/phpcollection

General-Purpose Collection Library for PHP

1.0k64.7M34](/packages/phpcollection-phpcollection)[aimeos/map

Easy and elegant handling of PHP arrays as array-like collection objects similar to jQuery and Laravel Collections

4.3k459.4k15](/packages/aimeos-map)[league/period

Time range API for PHP

7335.8M24](/packages/league-period)[loophp/collection

A (memory) friendly, easy, lazy and modular collection class.

745762.4k16](/packages/loophp-collection)[athari/yalinqo

YaLinqo, a LINQ-to-objects library for PHP

4581.2M5](/packages/athari-yalinqo)[lorisleiva/lody

Load files and classes as lazy collections in Laravel.

957.9M15](/packages/lorisleiva-lody)

PHPackages © 2026

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