Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- trait Singleton
- {
- private static $instance;
- private function __construct() {}
- public static function getInstance()
- {
- if (!(self::$instance instanceof self)) {
- self::$instance = new self;
- }
- return self::$instance;
- }
- }
- class MyClass
- {
- use Singleton;
- }
- $object = MyClass::getInstance(); // object of type MyClass
- $object = new MyClass; // PHP fatal error
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement