Advertisement
krot

Singleton

Jan 17th, 2017
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.50 KB | None | 0 0
  1. class Singleton
  2. {
  3.     private static $instance = null;
  4.     private $id=1;
  5.     public static function getInstance()
  6.     {
  7.         if (null === self::$instance)
  8.         {
  9.             self::$instance = new self();
  10.         }
  11.         return self::$instance;
  12.     }
  13.     private function __clone() {}
  14.     private function __construct() {}
  15.     public function myId()
  16.     {
  17.         return $this->id;
  18.     }
  19. }
  20. $Object = Singleton::getInstance();  // Получение объекта
  21. $Object -> myId();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement