How will i pass an array as key to __set magic method
<p>I have a php singleton session class as follows. </p>

<pre><code>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]);
    }


}
</code></pre>

<p>I can create an object as follows</p>

<pre><code>$session = Session::getInstance();
$session-&gt;name = 'some name';
</code></pre>

<p>I can also get the value like</p>

<pre><code>echo $session-&gt;name;
</code></pre>

<p>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</p>

<pre><code>$_SESSION['user']['data'] = array('name'=&gt;'some name',"empId"=&gt;'123');
</code></pre>

<p>I am trying like this.</p>

<pre><code>$session-&gt;['user']['data'] = array('name'=&gt;'some name',"empId"=&gt;'123');
</code></pre>

<p>but it is not working. Could you please suggest what is wrong. </p>
