PHPackages                             jced-artem/lazy-loading - 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. jced-artem/lazy-loading

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

jced-artem/lazy-loading
=======================

Quick simple lazy loading trait using reference property and closure

1.0.1(9y ago)018MITPHPPHP &gt;=5.5.0

Since Dec 1Pushed 9y ago1 watchersCompare

[ Source](https://github.com/jced-artem/lazy-loading)[ Packagist](https://packagist.org/packages/jced-artem/lazy-loading)[ Docs](https://github.com/jced-artem)[ RSS](/packages/jced-artem-lazy-loading/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

lazy-loading
============

[](#lazy-loading)

Quick simple lazy loading trait using reference property and closure

You do not need anymore to write something similar to implement lazy loading:

```
class ObjectFactory
{
    private $object;

    public function getObject()
    {
        if (empty($object)) {
            $this->object = new stdClass();
        }
        return $this->object;
    }
}

```

And, actually, you also do not need to keep in mind where you need to use `empty()`, `is_null()` or `$x === false`!

Just use LazyTrait:

```
class ObjectFactory
{
    use \Jced\LazyTrait;

    private $object1;
    private $object2;
    private $object3;
    private $object4;
    private $object5;

    public function getObject1()
    {
        // assert empty by default
        return $this->lazy($this->object1, new stdClass());
    }

    public function getObject2()
    {
        // assert empty by default
        return $this->lazy($this->object2, function() {
            return new stdClass();
        });
    }

    public function getObject3()
    {
        // assert is_null
        return $this->lazy($this->object3, new stdClass(), false, true);
    }

    public function getObject4()
    {
        // assert is false
        return $this->lazy($this->object4, new stdClass(), false, false, true);
    }

    public function getObject5()
    {
        // assert is false or empty or is_null
        return $this->lazy($this->object5, new stdClass(), true, true, true);
    }
}

```

### Install

[](#install)

`composer require jced-artem/lazy-loading`

### Notice

[](#notice)

Note that if you pass object as 'return' param - you will get reference. Use `new` or `clone` to prevent it if you need.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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

Total

2

Last Release

3434d ago

PHP version history (2 changes)1.0.0PHP &gt;=5.6.0

1.0.1PHP &gt;=5.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/694933bfd2d85dd295280dff0c339061f3652f3c65ad2a5427e429462b33e295?d=identicon)[jced\_artem](/maintainers/jced_artem)

---

Top Contributors

[![jced-artem](https://avatars.githubusercontent.com/u/1507915?v=4)](https://github.com/jced-artem "jced-artem (7 commits)")

---

Tags

lazy loadingtraitpattern

### Embed Badge

![Health badge](/badges/jced-artem-lazy-loading/health.svg)

```
[![Health](https://phpackages.com/badges/jced-artem-lazy-loading/health.svg)](https://phpackages.com/packages/jced-artem-lazy-loading)
```

###  Alternatives

[ocramius/proxy-manager

A library providing utilities to generate, instantiate and generally operate with Object Proxies

5.0k82.4M230](/packages/ocramius-proxy-manager)[symfony/var-exporter

Provides tools to export, instantiate, hydrate, clone and lazy-load PHP objects

2.1k378.1M441](/packages/symfony-var-exporter)[friendsofphp/proxy-manager-lts

Adding support for a wider range of PHP versions to ocramius/proxy-manager

1.2k139.1M104](/packages/friendsofphp-proxy-manager-lts)[nette/robot-loader

🍀 Nette RobotLoader: high performance and comfortable autoloader that will search and autoload classes within your application.

89152.7M321](/packages/nette-robot-loader)[league/pipeline

A plug and play pipeline implementation.

1.0k16.0M74](/packages/league-pipeline)[kkszymanowski/traitor

Add a trait use statement to existing PHP class

1305.2M16](/packages/kkszymanowski-traitor)

PHPackages © 2026

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