PHPackages                             phpnomad/singleton - 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. phpnomad/singleton

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

phpnomad/singleton
==================

1.0.1(3w ago)06.4k↓10.7%[1 PRs](https://github.com/phpnomad/singleton/pulls)6MITPHPCI passing

Since Oct 30Pushed 3w ago2 watchersCompare

[ Source](https://github.com/phpnomad/singleton)[ Packagist](https://packagist.org/packages/phpnomad/singleton)[ Docs](https://github.com/phpnomad/core)[ RSS](/packages/phpnomad-singleton/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (2)Dependencies (2)Versions (8)Used By (6)

phpnomad/singleton
==================

[](#phpnomadsingleton)

[![Latest Version](https://camo.githubusercontent.com/85dcd1f8c2d043a3e6bf2df37e927eae36c273fae6d70f5f7919de327f1743cb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068706e6f6d61642f73696e676c65746f6e2e737667)](https://packagist.org/packages/phpnomad/singleton) [![Total Downloads](https://camo.githubusercontent.com/edfcf3b59010c288443ca07ffd183a0ce5e1bc24d1d459b3b8df1a1fe35a0b21/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7068706e6f6d61642f73696e676c65746f6e2e737667)](https://packagist.org/packages/phpnomad/singleton) [![PHP Version](https://camo.githubusercontent.com/0e26670ffb500be362e98941e1d974c412f4d9f1f9837793acb9c92fa79fcd57/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7068706e6f6d61642f73696e676c65746f6e2e737667)](https://packagist.org/packages/phpnomad/singleton) [![License](https://camo.githubusercontent.com/92565bfad54c335098937839fa801cad8adb2cda63f370272d3a820666ca17db/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7068706e6f6d61642f73696e676c65746f6e2e737667)](https://packagist.org/packages/phpnomad/singleton)

`phpnomad/singleton` is a single-trait package for [PHPNomad](https://phpnomad.com). It provides `WithInstance`, a trait that gives any class a static `instance()` method returning a lazily-created, per-class singleton. It has zero runtime dependencies and is what `phpnomad/facade` and the rest of the framework use whenever a class needs a single shared instance without reaching for a container.

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

[](#installation)

```
composer require phpnomad/singleton
```

Quick Start
-----------

[](#quick-start)

Add the trait to a class, then call `instance()` to get the shared object.

```
