PHP code example of phptailors / singleton-interface

1. Go to this page and download the library: Download phptailors/singleton-interface library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phptailors / singleton-interface example snippets




use Tailors\Lib\Singleton\SingletonInterface;
use Tailors\Lib\Singleton\SingletonException;

final class MySingleton implements SingletonInterface
{
    private static ?MySingleton $instance = null;

    public static function getInstance(): MySingleton
    {
        if (null === self::$instance) {
            self::$instance = new self();
        }

        return self::$instance;
    }

    private function __construct() {}

    private function __clone() {}

    public function __wakeup()
    {
        throw new SingletonException('Cannot unserialize singleton '.self::class);
    }
}