How can the Singleton pattern be applied in PHP to handle situations where static methods need to create objects?

When static methods need to create objects in PHP, the Singleton pattern can be applied to ensure that only one instance of the object is created and used throughout the application. This pattern restricts the instantiation of a class to a single object, providing a global point of access to that instance.

class Singleton {
    private static $instance;

    private function __construct() {
        // Private constructor to prevent instantiation
    }

    public static function getInstance() {
        if (self::$instance === null) {
            self::$instance = new self();
        }
        return self::$instance;
    }
}

// Usage
$singletonInstance = Singleton::getInstance();