Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Class: Singleton
- *
- */
- class Singleton
- {
- /**
- * instance
- *
- * @var mixed
- */
- private static $instance;
- /**
- * name
- *
- * @var mixed
- */
- protected $name;
- /**
- * __construct
- *
- * @param mixed $name
- */
- private function __construct($name)
- {
- $this->name = $name;
- }
- /**
- * getInstance
- *
- * @param mixed $name
- */
- public static function getInstance($name) : Self
- {
- if (!isset(self::$instance)) {
- self::$instance = new Self($name);
- }
- return self::$instance;
- }
- /**
- * getName
- *
- */
- public function getName()
- {
- return $this->name;
- }
- }
- echo(Singleton::getInstance('Cvar1984'))->getName(), PHP_EOL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement