Singleton.php 348B

1234567891011121314151617181920212223
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: guanxl
  5. * Date: 2018/3/22
  6. * Time: 19:57
  7. */
  8. namespace App\Common;
  9. trait Singleton
  10. {
  11. private static $instance;
  12. static function getInstance(...$args)
  13. {
  14. if(!isset(self::$instance)){
  15. self::$instance = new static(...$args);
  16. }
  17. return self::$instance;
  18. }
  19. }