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

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

- Page: https://pluginprobe.com/plugins/yaymail/4.3.2/code/src/Utils/SingletonTrait.php
- Raw: https://pluginprobe.com/plugins/yaymail/4.3.2/raw/src/Utils/SingletonTrait.php
- Modified: 2025-12-17T13:01:26+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/4.3.2/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.' );
    }
}


```
