class Singleton { private static $instance; private function __construct() { // Private constructor to prevent the creation of new instances from outside } public static function getInstance() { if (!self::$instance) { self::$instance = new Singleton(); } return self::$instance; } }In the above example, we have a class called Singleton that has a private constructor to prevent the creation of new instances from outside the class. The getInstance method is defined as a public static method, which checks if an instance of the Singleton class has already been created. If an instance does not exist, then a new Singleton instance is created, and the same instance is returned for each subsequent call to the getInstance method. This pattern is commonly used in package libraries such as Laravel, Symfony, and CakePHP to manage objects with limited global scope and control over the application's life cycle.