class Controller { private static $instance; public static function getInstance() { if (self::$instance == null) { self::$instance = new Controller(); } return self::$instance; } private function __construct() { // private constructor to prevent instantiating directly } public function doSomething() { // some method logic } } // usage $controller = Controller::getInstance(); $controller->doSomething();
namespace MyApp\Controller; class HomeController { private static $instance; public static function getInstance() { if (self::$instance == null) { self::$instance = new HomeController(); } return self::$instance; } private function __construct() { // private constructor to prevent instantiating directly } public function index() { // some method logic } } // usage use MyApp\Controller\HomeController; $controller = HomeController::getInstance(); $controller->index();Based on the namespace and class name used in Example 2, it can be determined that this code is part of a package or library named "MyApp". The package or library might include other classes and methods for building web applications.