How will i pass an array as key to __set magic method

I have a singleton session class as follows.


<?php
class Session {
    static private $_instance = NULL;

    private function __construct()
	{
        session_start();
    }

    /**
	* Prevents the class from being cloned
	* @return NULL
	*/
	private function __clone() { }

	/**
	* Returns the singleton instance of this class
	* @return Session
	*/
    public static function getInstance()
	{
        if (!self::$_instance) {
            self::$_instance = new Session();
        }
        return self::$_instance;
    }

    public function __get($key) {
        if (isset($_SESSION[$key])) {
            return $_SESSION[$key];
        }
        return NULL;
    }

    public function __set($key, $value)
	{
        $_SESSION[$key] = $value;
    }
	
	public function __isset($key) {
        return isset($_SESSION[$key]);
    }

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

?>


I can create an object as follows

$session = Session::getInstance();
$session->name = ‘some name’;

I can also get the value like

echo $session->name;

The problem is, i want to pass an array to this object and it is not working. for example, i wan to set something like
$_SESSION[‘user’][‘data’] = array(‘name’=>‘some name’,“empId”=>‘123’);

I am trying like this.

$session->[‘user’][‘data’] = array(‘name’=>‘some name’,“empId”=>‘123’); but it is not working. Could you please suggest what is wrong.

You will need to implement the ArrayAccess interface, or possibly even extend [URL=“http://php.net/manual/en/class.arrayobject.php”]ArrayObject which already implements ArrayAccess.