How does the Singleton design pattern ensure that only one instance of a class is created in PHP?

The Singleton design pattern ensures that only one instance of a class is created by providing a static method to access the instance and ensuring that the constructor is private to prevent direct instantiation of the class.

class Singleton {
    private static $instance;

    private function __construct() {}

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