PHPackages                             stephenfrank/typedcollections - 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. stephenfrank/typedcollections

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

stephenfrank/typedcollections
=============================

Collection classes for strict(ish) typing

0.1.0(12y ago)013PHP

Since Mar 26Pushed 12y ago1 watchersCompare

[ Source](https://github.com/stephenfrank/typedcollections)[ Packagist](https://packagist.org/packages/stephenfrank/typedcollections)[ RSS](/packages/stephenfrank-typedcollections/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (2)Used By (0)

TypedCollections
================

[](#typedcollections)

`stephenfrank/typedcollections: "0.1.x"`

A collection of helper classes to enforce type safety in array collections.

TypedCollection (base class)
----------------------------

[](#typedcollection-base-class)

The base class is array-accessible and enforces type-strictness by checking each item added to the collection against the defined type.

The type can be defined through the constructor arguments or will be defined automatically based on the first item added.

```
$integerCollection = new TypedCollection([1, 2]);
$integerCollection[] = 'a'; // throws InvalidArgumentException

```

{*Type*}Collection
------------------

[](#typecollection)

Several classes have built-in types for strict checking against:

- bools `BoolCollection`
- integers `IntegerCollection`
- floats `FloatCollection`
- strings `StringCollection`
- array `ArrayCollection`
- objects `ObjectCollection`

```
$stringCollection = new StringCollection;
$stringCollection[] = 'foo';
$stringCollection[] = true; // throws InvalidArgumentException

```

ClassCollection
---------------

[](#classcollection)

The ClassCollection will check that each item added to the array is of a particular class using `get_class()`.

```
$foosCollection = new ClassCollection([new Foo]);
// or new ClassCollection([new Foo], 'Foo');
$stringCollection[] = new StdClass; // throws InvalidArgumentException

```

InstanceCollection
------------------

[](#instancecollection)

The InstanceCollection will check each item using `instanceof` so that collections can be defined by an interface or inherited class.

```
$foosCollection = new InstanceCollection([
	new ArrayObject,
	new ArrayIterator
], 'ArrayAccess'); // This is A-okay

```

What’s the point?
-----------------

[](#whats-the-point)

Sometimes type strictness is important when exposing a public API in a framework or library. Effectively it reduces the number of places where the API consumer can shoot themselves in the foot.

```
class NumberAdder
{
	public function sum(NumericCollection $numerics);
}

```

Sometimes when using a third-party/legacy library you might want type-check against the kind of garbage they return and raise an exception when they don't return clean data

```
$resources = new ClassCollection($thirdPartyThinger->getResources(), 'AcmeResource');
// Will explode if [] is not returned

```

Lastly, `InstanceCollection` makes it super easy to create your own typed collections.

```
class AcmeResourceCollection extends InstanceCollection
{
	protected $type = 'AcmeResource';
}

```

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

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

Unknown

Total

1

Last Release

4479d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/112059?v=4)[Stephen Frank](/maintainers/stephenfrank)[@stephenfrank](https://github.com/stephenfrank)

---

Top Contributors

[![stephenfrank](https://avatars.githubusercontent.com/u/112059?v=4)](https://github.com/stephenfrank "stephenfrank (2 commits)")

### Embed Badge

![Health badge](/badges/stephenfrank-typedcollections/health.svg)

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

###  Alternatives

[markshust/magento2-module-extrabodyclasses

The Extra Body Classes module adds the website and store codes to the body class attribute.

331.8k](/packages/markshust-magento2-module-extrabodyclasses)

PHPackages © 2026

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