I am using a magic getter/setter class for my session variables, but I don't see any difference between normal setters and getters.
The code:
class session
{
public function __set($name, $value)
{
$_SESSION[$name] = $value;
}
public function __unset($name)
{
unset($_SESSION[$name]);
}
public function __get($name)
{
if(isset($_SESSION[$name]))
{
return $_SESSION[$name];
}
}
}
Now the first thing I noticed is that I have to call $session->_unset('var_name')
to remove the variable, nothing 'magical' about that.
Secondly when I try to use $session->some_var
this does not work. I can only get the session variable using $_SESSION['some_var']
.
I have looked at the PHP manual but the functions look the same as mine.
Am I doing something wrong, or is there not really anything magic about these functions.