<?php
/**
 * Created by PhpStorm.
 * User: wangchen
 * Date: 2019-04-23
 * Time: 11:42
 */

namespace App\Libs;

trait Singleton
{
    /**
     * 该属性用来保存实例
     * @var
     */
    private static $instance;

    /**
     * 创建一个用来实例化对象的方法
     */
    public static function getInstance(...$args)
    {
        if (!(self::$instance instanceof self)) {
            self::$instance = new static($args); // 后期静态绑定
        }
        return self::$instance;
    }

    /**
     * 构造函数为private,防止创建对象
     */
    public function __construct()
    {
    }

    /**
     * 防止对象被复制
     */
    private function __clone()
    {
        trigger_error('Clone is not allowed!');
    }
}