# yaymail/trunk/src/Utils/SingletonTrait.php

YayMail – WooCommerce Email Customizer, version trunk. 25 lines.

- Page: https://pluginprobe.com/plugins/yaymail/trunk/code/src/Utils/SingletonTrait.php
- Raw: https://pluginprobe.com/plugins/yaymail/trunk/raw/src/Utils/SingletonTrait.php
- Modified: 2025-05-19T11:32:38+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/yaymail/trunk/code/src/Utils/SingletonTrait.php#L10-L20`.

```php
<?php
namespace YayMail\Utils;

trait SingletonTrait {
    private static $instance;

    public static function get_instance( ...$args ) {
        $class = get_called_class();
        if ( ! $class::$instance ) {
            $class::$instance = new $class( ...$args );
        }

        return $class::$instance;
    }

    /** Singletons should not be cloneable. */
    protected function __clone() { }

    /** Singletons should not be restorable from strings. */
    public function __wakeup() {
        throw new \Exception( 'Cannot unserialize a singleton.' );
    }
}


```
