Singletons are classes which can only be instantiated once. You can effectively only have one object per Singleton
class in an application. If you've never heard of Singletons before you may jump into the air thinking "Yes! I have a million and one use cases for this!" Well, please don't. Singletons are just terrible and can be effectively avoided.
So, a Singleton
class in PHP looks something like this:
<?php class Singleton { private static $instance; public static function getInstance() { if (null === static::$instance) { static::$instance = new static(); } return static::$instance; } protected function __construct() { } private function __clone() { } private function __wakeup() { } }
So here are the reasons...