class Config {
private static ?self $instance = null;
private function __construct() {}
public static function getInstance(): self {
self::$instance ??= new self();
return self::$instance;
}
}Singleton is one of the most criticised patterns. It introduces global state, complicates testing (hard to replace with a mock), and violates Dependency Inversion. In modern code it is replaced by registering the dependency as a singleton in an IoC container.