# wp-console/2.5.1/includes/Traits/Singleton.php

WP Console – WordPress PHP Console powered by PsySH, version 2.5.1. 40 lines.

- Page: https://pluginprobe.com/plugins/wp-console/2.5.1/code/includes/Traits/Singleton.php
- Raw: https://pluginprobe.com/plugins/wp-console/2.5.1/raw/includes/Traits/Singleton.php
- Modified: 2019-06-21T07:43:36+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/wp-console/2.5.1/code/includes/Traits/Singleton.php#L10-L20`.

```php
<?php

namespace WPConsole\Traits;

/**
 * Singleton Trait
 *
 * @since 1.0.0
 */
trait Singleton {

    /**
     * Singleton class instance holder
     *
     * @since 1.0.0
     *
     * @var object
     */
    private static $instance;

    /**
     * Make a class instance
     *
     * @since 1.0.0
     *
     * @return object
     */
    public static function instance() {
        if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) {
            self::$instance = new self();

            if ( method_exists( self::$instance, 'boot' ) ) {
                self::$instance->boot();
            }
        }

        return self::$instance;
    }
}

```
