storage =& $storage; // Load dynamically existing session variables into object properties foreach ($storage as $key => $value) { $this->$key = $value; } } /** * Get all session variables * * @access public * @return array */ public function getAll() { $session = get_object_vars($this); unset($session['storage']); return $session; } /** * Copy class properties to external storage * * @access public */ public function __destruct() { $this->storage = $this->getAll(); } }