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

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

piotrpress/typed-collection
===========================

A strict typed collection for PHP with runtime validation for scalar and object-based item types.

v1.0.0(today)00MITPHPPHP &gt;=8.2

Since Aug 24Pushed todayCompare

[ Source](https://github.com/PiotrPress/typed-collection)[ Packagist](https://packagist.org/packages/piotrpress/typed-collection)[ Docs](https://github.com/PiotrPress/typed-collection)[ RSS](/packages/piotrpress-typed-collection/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (2)Used By (0)

Typed Collection
================

[](#typed-collection)

A strict typed collection for PHP with runtime validation for scalar and object-based item types.

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

[](#installation)

```
composer require piotrpress/typed-collection
```

Example
-------

[](#example)

```
require_once __DIR__ . '/vendor/autoload.php';

use PiotrPress\TypedCollection;

$collection = new TypedCollection( type: Example::class, values: [ new Example() ] );

$collection[0]; // returns Example instance from key 0 of the collection
$collection[] = new Example(); // adds new Example instance to the collection
foreach( $collection as $value ) // iterates over the collection
```

Usage
-----

[](#usage)

```
use PiotrPress\TypedCollection;
use PiotrPress\TypedCollection\Type;

new TypedCollection( Type|string $type, array $values = [] );
```

### Parameters

[](#parameters)

- `type` - the type of the collection. Can be `Class`, `Interface` or `Enum` name or one of the following:
    - `Type:String`
    - `Type:Int`
    - `Type:Float`
    - `Type:Bool`
    - `Type:Array`
    - `Type:Object`
    - `Type:Callable`
    - `Type:Iterable`
- `values` - an array of values to initialize the collection with. All values must be of the specified type.

### Methods

[](#methods)

`TypedCollection` extends `ArrayObject`, for more information about the methods available, please refer to the [PHP documentation](https://www.php.net/manual/en/class.arrayobject.php).

Development
-----------

[](#development)

```
docker compose run --rm php composer install
docker compose run --rm php composer format
docker compose run --rm php composer test
```

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

[](#requirements)

- PHP `>= 8.1`

License
-------

[](#license)

[MIT](license.txt)

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance100

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

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

Unknown

Total

1

Last Release

0d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10326736?v=4)[Piotr Niewiadomski](/maintainers/PiotrPress)[@PiotrPress](https://github.com/PiotrPress)

---

Top Contributors

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

---

Tags

arraycollectioniterableArrayAccesstyped-collectionphp collectionobject collectionstrict collectionphp typed collectionscalar collection

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[aimeos/map

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

4.3k475.2k19](/packages/aimeos-map)[rotexsoft/versatile-collections

A collection package that can be extended to implement things such as a Dependency Injection Container, RecordSet objects for housing database records, a bag of http cookies, or technically any collection of items that can be looped over and whose items can each be accessed using array-access syntax or object property syntax.

186.1k1](/packages/rotexsoft-versatile-collections)[athari/yalinqo

YaLinqo, a LINQ-to-objects library for PHP

4531.2M5](/packages/athari-yalinqo)[yansongda/supports

common components

211.4M32](/packages/yansongda-supports)[armincms/json

A Laravel Nova field.

25160.1k3](/packages/armincms-json)[graze/data-structure

Data collections and containers

12298.5k10](/packages/graze-data-structure)

PHPackages © 2026

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