PHPackages                             ngmy/typed-array - 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. ngmy/typed-array

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

ngmy/typed-array
================

The typed array for PHP

0.11.0(5y ago)11.6k[1 PRs](https://github.com/ngmy/php-typed-array/pulls)2MITPHPPHP ^7.3|^8.0

Since Feb 16Pushed 5y ago1 watchersCompare

[ Source](https://github.com/ngmy/php-typed-array)[ Packagist](https://packagist.org/packages/ngmy/typed-array)[ Fund](https://flattr.com/@ngmy)[ GitHub Sponsors](https://github.com/ngmy)[ RSS](/packages/ngmy-typed-array/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependenciesVersions (13)Used By (2)

PHP Typed Array
===============

[](#php-typed-array)

[![Latest Stable Version](https://camo.githubusercontent.com/68adfe7eaffeeab9e334037bfc400836a16273bad4da5664ebb2d9c24fdbaff8/68747470733a2f2f706f7365722e707567782e6f72672f6e676d792f74797065642d61727261792f76)](//packagist.org/packages/ngmy/typed-array)[![Total Downloads](https://camo.githubusercontent.com/5162609254fe74ead4db41df1b20104f7f822dbbf773123a9ded57366855b73f/68747470733a2f2f706f7365722e707567782e6f72672f6e676d792f74797065642d61727261792f646f776e6c6f616473)](//packagist.org/packages/ngmy/typed-array)[![Latest Unstable Version](https://camo.githubusercontent.com/2391bab2cec03bb15e96bcbcdfb169fd56509d8d4f76c3a62cb688e1c0b9aaa3/68747470733a2f2f706f7365722e707567782e6f72672f6e676d792f74797065642d61727261792f762f756e737461626c65)](//packagist.org/packages/ngmy/typed-array)[![License](https://camo.githubusercontent.com/47b872c90094e39024378fd43cfd9708eca61dab58a1db57f278efc1f3022afd/68747470733a2f2f706f7365722e707567782e6f72672f6e676d792f74797065642d61727261792f6c6963656e7365)](//packagist.org/packages/ngmy/typed-array)[![composer.lock](https://camo.githubusercontent.com/7480048210a7403ae251a51fc610636300dcb25c99616e0aa8b200f53a7c2b73/68747470733a2f2f706f7365722e707567782e6f72672f6e676d792f74797065642d61727261792f636f6d706f7365726c6f636b)](//packagist.org/packages/ngmy/typed-array)[![PHP CI](https://github.com/ngmy/php-typed-array/actions/workflows/php.yml/badge.svg)](https://github.com/ngmy/php-typed-array/actions/workflows/php.yml)[![Coverage Status](https://camo.githubusercontent.com/35bf42db24dc5ec81dc1832821770328144bfb9d306c5dfa5320398952f95f65/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6e676d792f7068702d74797065642d61727261792f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/ngmy/php-typed-array?branch=master)[![PHPStan](https://camo.githubusercontent.com/441b5874ce4df0a2defc892979c96c46889b69cb32119d04f0b48626349f8bc9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d656e61626c65642d627269676874677265656e2e7376673f7374796c653d666c6174)](https://github.com/phpstan/phpstan)[![Psalm Coverage](https://camo.githubusercontent.com/b291d2292f0a792eaf1586895cb0784336f0ce6737a5ea24b9ba3111779b5374/68747470733a2f2f73686570686572642e6465762f6769746875622f6e676d792f7068702d74797065642d61727261792f636f7665726167652e7376673f)](https://shepherd.dev/github/ngmy/php-typed-array)[![Psalm Level](https://camo.githubusercontent.com/ae7dc350f954ae6008c8fdf890c0aaa2251008c0224a9df7c3cdcf47e2fc13b7/68747470733a2f2f73686570686572642e6465762f6769746875622f6e676d792f7068702d74797065642d61727261792f6c6576656c2e7376673f)](https://shepherd.dev/github/ngmy/php-typed-array)

PHP Typed Array is the typed array for PHP.

- Can create the typed array with the specified key and value type
- Can specify the bool, float, int, object, resource, or string type, or the specified class type, or the class type that implements the specified interface, or the class type that uses the specified trait for the key type
- Can specify the array, bool, float, int, object, resource, or string type, or the specified class type, or the class type that implements the specified interface, or the class type that uses the specified trait for the value type
- Implements the `ArrayAccess`, `Countable`, and `IteratorAggregate` interfaces
- Supports the static analysis like PHPStan and Psalm. Please see [examples](docs/examples)

```
// Returns a new instance of the typed array with the int type value
$intArray = Ngmy\TypedArray\TypedArray::new()->withIntValue(); // TypedArray

$intArray[] = 1;      // Good
// $intArray[] = '2'; // No good. The InvalidArgumentException exception is thrown

// Returns a new instance of the typed array with the class type value that implements the DateTimeInterface interface
$dateTimeInterfaceArray = Ngmy\TypedArray\TypedArray::new()
    ->withInterfaceValue(DateTimeInterface::class); // TypedArray

$dateTimeInterfaceArray[] = new DateTime();          // Good
$dateTimeInterfaceArray[] = new DateTimeImmutable(); // Good
// $dateTimeInterfaceArray[] = new stdClass();       // No good. The InvalidArgumentException exception is thrown

foreach ($dateTimeInterfaceArray as $dateTime) {
    echo $dateTime->format('Y-m-d H:i:s') . PHP_EOL;
}

// Determines if the typed array is empty or not
echo var_export($dateTimeInterfaceArray->isEmpty(), true) . PHP_EOL; // false

// Gets the typed array of items as a plain array
print_r($dateTimeInterfaceArray->toArray());
// Array
// (
//     [0] => DateTime Object
//         ...
//     [1] => DateTimeImmutable Object
//         ...
// )

// You can also specify the type of the key
$stringKeyArray = Ngmy\TypedArray\TypedArray::new()->withStringKey(); // TypedArray
$stringKeyArray['foo'] = 1; // Good
// $stringKeyArray[] = 2;   // No good. The InvalidArgumentException exception is thrown

// Of course, you can also specify the type of both the key and the value
$intStringArray = Ngmy\TypedArray\TypedArray::new()->withIntKey()->withStringValue(); // TypedArray
```

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

[](#requirements)

PHP Typed Array has the following requirements:

- PHP &gt;= 7.3

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

[](#installation)

Execute the Composer `require` command:

```
composer require ngmy/typed-array
```

Documentation
-------------

[](#documentation)

Please see the [API documentation](https://ngmy.github.io/php-typed-array/api/).

License
-------

[](#license)

PHP Typed Array is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity55

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

Total

11

Last Release

1869d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/864041?v=4)[Yuta Nagamiya](/maintainers/ngmy)[@ngmy](https://github.com/ngmy)

---

Top Contributors

[![ngmy](https://avatars.githubusercontent.com/u/864041?v=4)](https://github.com/ngmy "ngmy (121 commits)")

---

Tags

arraylibraryphpphp-librarytypetyped-arraytypearrayTyped Array

### Embed Badge

![Health badge](/badges/ngmy-typed-array/health.svg)

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

###  Alternatives

[doctrine/collections

PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.

6.0k411.1M1.2k](/packages/doctrine-collections)[phpoption/phpoption

Option Type for PHP

2.7k541.2M159](/packages/phpoption-phpoption)[symfony/property-access

Provides functions to read and write from/to an object or array using a simple string notation

2.8k295.3M2.5k](/packages/symfony-property-access)[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[league/config

Define configuration arrays with strict schemas and access values with dot notation

564302.2M24](/packages/league-config)[jetbrains/phpstorm-stubs

PHP runtime &amp; extensions header files for PhpStorm

1.4k27.7M68](/packages/jetbrains-phpstorm-stubs)

PHPackages © 2026

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