Singleton - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of Singleton.php
- <?php
- class DbConnector {
- private static $instances = [];
- protected function __construct() { }
- protected function __clone() { }
- public function __wakeup() {
- throw new \Exception("Cannot unserialized singleton");
- }
- public static function getInstance() {
- $subclass = static::class;
- if(!isset(self::$instances[$subclass])) {
- self::$instances[$subclass] = new static;
- }
- return self::$instances[$subclass];
- }
- }
File Description
- Singleton
- PHP Code
- 06 Nov-2019
- 506 Bytes
You can Share it:
Latest PHP Pastes