I have a class for session handling that uses object overloading for __GET and __SET, I've been having issues with arrays and read to assign get by reference, such as &__GET
The problem is I can't update the values. For example, let's say I have this:
$session->item['one']['name']
I'd like to change it, by assigning it a new value; $session->item['one']['name'] = 'new value' However, it doesn't change.
Any ideas how to work around this? Below is the code, thank you!
class Session
{
private $_session = array();
public function __construct()
{
if(!isset($_SESSION)) {
session_start();
}
$this->_session = $_SESSION;
}
public function __isset($name)
{
return isset($this->_session[$name]);
}
public function __unset($name)
{
unset($_SESSION[$name]);
unset($this->_session[$name]);
}
public function &__get($name)
{
return $this->_session[$name];
}
public function __set($name, $val)
{
$_SESSION[$name] = $val;
$this->_session[$name] = $val;
}
public function getSession()
{
return (isset($this->_session)) ? $this->_session : false;
}
public function getSessionId()
{
return (isset($_SESSION)) ? session_id() : false;
}
public function destroy()
{
$_SESSION = array();
session_destroy();
session_write_close();
unset($this->_session);
}
}
$_SESSION, but have you tried doing$this->_session = &$_SESSION;in your constructor instead of how you're setting it now?