makhnanov / php-global-singleton
There is no license information available for the latest version (dev-main) of this package.
PHP Singleton Implementation.
dev-main
2025-07-29 15:24 UTC
Requires
- php: >=8.4
This package is auto-updated.
Last update: 2025-07-29 15:24:49 UTC
README
Install
composer require makhnanov/php-global-singleton
Requirements
PHP >= 8.4
Source Code
<?php declare(strict_types=1); class GlobalSingleton { protected static array $instances = []; public static function one(): static { $class = static::class; if (isset(static::$instances[$class])) { return static::$instances[$class]; } return static::$instances[$class] = new static(); } protected function __construct() { } }
Usage
class Configurator extends GlobalSingleton { } Configurator::one(); new Configurator(); // Not Works