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

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

linna/typed-array
=================

Linna Typed Array, typed arrays for PHP

v3.0.1(3y ago)88.4k↓72.6%3[1 PRs](https://github.com/linna/typed-array/pulls)2MITPHPPHP &gt;=8.1CI failing

Since Jun 7Pushed 3y ago2 watchersCompare

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

READMEChangelog (10)Dependencies (3)Versions (14)Used By (2)

 [![Linna Logo](logo-linna-128.png)](#)

 [![Linna dotenv Logo](logo-array.png)](#)

[![Tests](https://github.com/linna/typed-array/actions/workflows/tests.yml/badge.svg)](https://github.com/linna/typed-array/actions/workflows/tests.yml)[![Quality Gate Status](https://camo.githubusercontent.com/f2070f2ce847cedf7cf40c01da8a849f70f5e991e626142acdf1ea61e45ffd8d/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d6c696e6e615f74797065642d6172726179266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/summary/new_code?id=linna_typed-array)[![PDS Skeleton](https://camo.githubusercontent.com/3c7140ee36205075ed977142f25c29eb1fb7809e9b86a865461fc21776ad1665/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7064732d736b656c65746f6e2d626c75652e7376673f7374796c653d666c6174)](https://github.com/php-pds/skeleton)[![PHP 8.1](https://camo.githubusercontent.com/1c708345a94c698fd596459da39a9535062cfa1162a57a8ae4e3cdd54e00a25d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312d3838393242462e737667)](http://php.net)

About
-----

[](#about)

This package provide typed arrays for php as extension of native [ArrayObject](http://php.net/manual/en/class.arrayobject.php).

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

[](#requirements)

This package require php 8.1

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

[](#installation)

With composer:

```
composer require linna/typed-array

```

Classes
-------

[](#classes)

NameNative Type HandledDescription`ArrayOfArrays`array`ArrayOfBooleans`bool`ArrayOfCallable`callable`ArrayOfClasses`any existing classpassed as first argument in constructor as `::class``ArrayOfFloats`float`ArrayOfIntegers`int`ArrayOfObjects`object`ArrayOfStrings`stringUsage
-----

[](#usage)

```
use Linna\TypedArrayObject\ArrayOfIntegers;
use Linna\TypedArrayObject\ArrayOfClasses;

//correct, only int passed to constructor.
$intArray = new ArrayOfIntegers([1, 2, 3, 4]);

//correct, int assigned
$intArray[] = 5;
//throw InvalidArgumentException, string assigned, int expected.
$intArray[] = 'a';

//correct, int used
$intArray->append(5);
//throw InvalidArgumentException, string used, int expected.
$intArray->append('a');

//throw InvalidArgumentException, mixed array passed to constructor.
$otherIntArray = new ArrayOfIntegers([1, 'a', 3, 4]);

//correct, only Foo class instances passed to constructor.
$fooArray = new ArrayOfClasses(Foo::class, [
    new Foo(),
    new Foo()
]);

//correct, Foo() instance assigned.
$fooArray[] = new Foo();
//throw InvalidArgumentException, Bar() instance assigned.
$fooArray[] = new Bar();

//correct, Foo() instance used.
$fooArray->append(new Foo());
//throw InvalidArgumentException, Bar() instance used, Foo() instance expected.
$fooArray->append(new Bar());

//throw InvalidArgumentException, mixed array of instances passed to constructor.
$otherFooArray = new ArrayOfClasses(Foo::class, [
    new Foo(),
    new Bar()
]);
```

> **Note:** Allowed types are: *array*, *bool*, *callable*, *float*, *int*, *object*, *string* and all existing classes.

Performance consideration for v3.0
----------------------------------

[](#performance-consideration-for-v30)

Compared to previous versions of the library, this version is a bit faster because every types has it own class. Do milliseconds really matters?

[![Array Speed Test](array-speed-test-v3.png)](array-speed-test-v3.png)

Performance consideration for v2.0
----------------------------------

[](#performance-consideration-for-v20)

Compared to first version of the library, this version is a bit slower because after merging `TypedObjectArray` with `TypedArray`, there are more code that be executed when new instance is created and on assign operations.

[![Array Speed Test](array-speed-test-v2.png)](array-speed-test-v2.png)

Performance consideration for v1.0
----------------------------------

[](#performance-consideration-for-v10)

Compared to the parent class [ArrayObject](http://php.net/manual/en/class.arrayobject.php) typed arrays are slower on writing approximately from 6x to 8x. The slowness is due to not native `__construct()` and not native `offsetSet()`.
Other operations do not have a speed difference with the native ArrayObject.

```
use Linna\TypedArray;

//slower from 6x to 8x.
$array = new TypedArray('int', [1, 2, 3, 4]);
$array[] = 5;

//other operations, fast as native.
//for example:
$arrayElement = $array[0];
$elements = $array->count();
```

[![Array Speed Test](array-speed-test.png)](array-speed-test.png)View the speed test script on [gist](https://gist.github.com/s3b4stian/9441af5855b795cc1569b3cdb5e7526d).

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor1

Top contributor holds 99.2% 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 ~230 days

Recently: every ~410 days

Total

10

Last Release

1241d ago

Major Versions

v1.0.5 → v2.0.02018-08-13

v2.0.1 → v3.0.02022-05-13

PHP version history (5 changes)v1.0.0PHP ^7.0.0

v1.0.5PHP ^7.0

v2.0.0PHP ^7.1

v2.0.1PHP &gt;=7.1

v3.0.0PHP &gt;=8.1

### Community

Maintainers

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

---

Top Contributors

[![s3b4stian](https://avatars.githubusercontent.com/u/11441761?v=4)](https://github.com/s3b4stian "s3b4stian (126 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

---

Tags

arrayobjectperformance-considerationsphptypetypedarrayphparrayTyped Array

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[zakirullin/mess

Convenient array-related routine &amp; better type casting

21330.5k2](/packages/zakirullin-mess)

PHPackages © 2026

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