How can the Singleton design pattern be utilized in PHP to optimize code efficiency?

The Singleton design pattern can be utilized in PHP to optimize code efficiency by ensuring that only one instance of a class is created and providing a global point of access to that instance. This can prevent unnecessary instantiation of multiple objects and reduce memory usage in situations where a single instance is sufficient.

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();