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

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

lianhua/singleton
=================

A simple PHP class for singleton

2.0(6y ago)025GPL-3.0PHP

Since Mar 23Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Nevermille/Singleton)[ Packagist](https://packagist.org/packages/lianhua/singleton)[ RSS](/packages/lianhua-singleton/feed)WikiDiscussions master Synced 4d ago

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

Singleton
=========

[](#singleton)

[![Build Status](https://camo.githubusercontent.com/a62909ab9fd4ec3c5dcfd21f80514c1028e7a0737a301293025135fbf77168ca/68747470733a2f2f7472617669732d63692e636f6d2f4e657665726d696c6c652f53696e676c65746f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/Nevermille/Singleton) [![BCH compliance](https://camo.githubusercontent.com/998bcddabb45f999fb4f8070ec3636c60a20f658f3930b619551d0269116bfbf/68747470733a2f2f626574746572636f64656875622e636f6d2f656467652f62616467652f4e657665726d696c6c652f53696e676c65746f6e3f6272616e63683d6d6173746572)](https://bettercodehub.com/)

Overview
--------

[](#overview)

A simple PHP class for singleton

Compatibility
-------------

[](#compatibility)

This library has been tested for PHP 7.3 and higher

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

[](#installation)

Just use composer in your project:

```
composer require lianhua/singleton

```

Usage
-----

[](#usage)

Create a class using \\Lianhua\\Singleton\\Singleton trait, that's all.

```
class MySingleton
{
    use \Lianhua\Singleton\Singleton;
    // Your methods and properties here
}
```

If you need a constructor, make sure it's a protected one

```
class MySingleton
{
    use \Lianhua\Singleton\Singleton;

    private $n;

    protected function __construct()
    {
        $this->n = 0;
    }
}
```

Upgrading
---------

[](#upgrading)

### From 1.0 to 2.0

[](#from-10-to-20)

Singleton became a trait instead of a class in order to create many singleton classes. Please edit your class like this:

**Then**

```
class MySingleton extends \Lianhua\Singleton\Singleton
{
    private $n;

    protected function __construct()
    {
        $this->n = 0;
    }
}
```

**Now**

```
class MySingleton
{
    use \Lianhua\Singleton\Singleton;

    private $n;

    protected function __construct()
    {
        $this->n = 0;
    }
}
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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

Total

2

Last Release

2228d ago

Major Versions

1.0 → 2.02020-04-08

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/38858480?v=4)[Camille Nevermind](/maintainers/Nevermille)[@nevermille](https://github.com/nevermille)

---

Top Contributors

[![nevermille](https://avatars.githubusercontent.com/u/38858480?v=4)](https://github.com/nevermille "nevermille (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/lianhua-singleton/health.svg)

```
[![Health](https://phpackages.com/badges/lianhua-singleton/health.svg)](https://phpackages.com/packages/lianhua-singleton)
```

###  Alternatives

[aura/payload

A Domain Payload implementation.

56370.4k9](/packages/aura-payload)[barrelstrength/sprout-seo

1133.7k1](/packages/barrelstrength-sprout-seo)

PHPackages © 2026

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