What is the purpose of using a SessionStorage class in PHP for managing session data?

SessionStorage class in PHP is used for managing session data in a more structured and organized manner. It allows developers to easily store and retrieve session variables without directly interacting with the $_SESSION superglobal. This can help improve code readability and maintainability by encapsulating session-related logic in a dedicated class.

<?php

class SessionStorage {
    public static function set($key, $value) {
        $_SESSION[$key] = $value;
    }

    public static function get($key) {
        return $_SESSION[$key] ?? null;
    }

    public static function delete($key) {
        unset($_SESSION[$key]);
    }
}

// Example usage
SessionStorage::set('user_id', 123);
$user_id = SessionStorage::get('user_id');
SessionStorage::delete('user_id');

?>