PHPackages                             thecodingmachine/lazy-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. thecodingmachine/lazy-array

ActiveLibrary

thecodingmachine/lazy-array
===========================

This package provides an array than can lazily instantiate the objects it contains.

1.0.x-dev(10y ago)16MITPHPPHP &gt;=5.6

Since Apr 12Pushed 10y ago6 watchersCompare

[ Source](https://github.com/thecodingmachine/lazy-array)[ Packagist](https://packagist.org/packages/thecodingmachine/lazy-array)[ RSS](/packages/thecodingmachine-lazy-array/feed)WikiDiscussions 1.0 Synced 2mo ago

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

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/7bca5b4462bd56d6ace6f1f317cce57ef347744d18cb3f0ca4f51f7da3f3bbe8/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f746865636f64696e676d616368696e652f6c617a792d61727261792f6261646765732f7175616c6974792d73636f72652e706e673f623d312e30)](https://scrutinizer-ci.com/g/thecodingmachine/lazy-array/?branch=1.0)[![Build Status](https://camo.githubusercontent.com/735f99241c63ca820ce6d5d694164763017c578745dadc9f43af054afa2d2c8e/68747470733a2f2f7472617669732d63692e6f72672f746865636f64696e676d616368696e652f6c617a792d61727261792e7376673f6272616e63683d312e30)](https://travis-ci.org/thecodingmachine/lazy-array)[![Coverage Status](https://camo.githubusercontent.com/49924e02f07b871e5d5107a52d5885ef4999ac88364a51432a6a136c4f6a7c56/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f746865636f64696e676d616368696e652f6c617a792d61727261792f62616467652e7376673f6272616e63683d312e3026736572766963653d676974687562)](https://coveralls.io/github/thecodingmachine/lazy-array?branch=1.0)

What is it?
===========

[](#what-is-it)

This project contains a single class that behaves like an array. However, objects in this array can be instantiated only when the key in the array is fetched, so you don't have to create the instance right away. This is useful for performance considerations.

How does it work?
=================

[](#how-does-it-work)

Easy, you create a new `LazyArray` object, and then, you push objects in it.

```
$lazyArray = new LazyArray();

$key = $lazyArray->push(MyServiceProvider::class);

// This will trigger the creation of the MyServiceProvider object and return it.
$serviceProvider = $lazyArray[$key];
```

You can also pass parameters to the constructor of the object:

```
$lazyArray = new LazyArray();

$key = $lazyArray->push(MyServiceProvider::class, "param1", "param2");
```

And because we are kind, you can also push into the lazy array an already instantiated object:

```
$lazyArray = new LazyArray();

// This is possible, even if we loose the interest of the LazyArray.
$key = $lazyArray->push(new MyServiceProvider());
```

Finally, if you are performance oriented (and I'm sure you are), you can create the whole lazy array in one call:

```
$lazyArray = new LazyArray([
    MyServiceProvider::class, // Is you simply want to create an instance without passing parameters
    [ MyServiceProvider2::class, [ "param1", "param2 ] ],  // Is you simply want to create an instance and pass parameters to the constructor
    new MyServiceProvider4('foo') // If you directly want to push the constructed instance.
]);
```

Why?
====

[](#why)

As the examples suggest, this was built for improving the performance of service providers loading (in compiled container environment). Do not use this as a replacement for a dependency injection container, this is a bad idea.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity42

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

3685d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1104771?v=4)[mouf](/maintainers/mouf)[@Mouf](https://github.com/Mouf)

![](https://avatars.githubusercontent.com/u/1847918?v=4)[TheCodingMachine](/maintainers/thecodingmachine)[@thecodingmachine](https://github.com/thecodingmachine)

---

Top Contributors

[![moufmouf](https://avatars.githubusercontent.com/u/1290952?v=4)](https://github.com/moufmouf "moufmouf (5 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/thecodingmachine-lazy-array/health.svg)

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

PHPackages © 2026

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