How does lazy instantiation apply to variables in PHP, and how does it relate to Singleton patterns?

Lazy instantiation in PHP refers to delaying the creation of an object until it is actually needed, rather than creating it immediately. This can help improve performance by only creating objects when they are required. In the context of Singleton patterns, lazy instantiation ensures that only one instance of a class is created when it is first accessed, and subsequent calls return the same instance.

class Singleton {
    private static $instance = null;

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

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