Creational --- Singleton
Purpose:
This is considered to be an ANTI-PATTERN! We could use dependency injection to replace this pattern.
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。To have only one instance of object in the application that will handle all calls.
<?php namespace DesignPatterns\Creational\Singleton; final class Singleton { /** * @var Singleton */ private static $instance; /** * Gets the instance via lazy initialization (created on first usage) * * @return Return Singleton */ public static function getInstance(): Singleton { if (null === static::$instance) { static::$instance = new static(); } return static::$instance; } /** * Private the constructor * * @return Void */ private function __construct() { // Code Here } /** * Prevent the instnace from being cloned (which would create a second instance of it) * * @return Void */ private function __clone() { // Code Here } /** * Prevent from being unserialized (which would create a second instance of it) * * @return Return */ private function __weakup() { // Code Here } }

更多精彩