hyperf-chat/app/Traits/StaticInstance.php

33 lines
446 B
PHP
Raw Normal View History

2021-05-21 22:56:42 +08:00
<?php
namespace App\Traits;
/**
* Trait StaticInstance
*
* @package App\Traits
*/
trait StaticInstance
{
private static $instance;
/**
* 获取单例
*
* @return static
*/
static public function getInstance()
{
if (!(self::$instance instanceof static)) {
self::$instance = new static();
}
return self::$instance;
}
private function __clone()
{
}
}