You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Matthew McNaney edited this page Jun 6, 2013
·
2 revisions
Session is a replacement class for the $_SESSION array. Obviously, the superglobal is still being used, but the variables are controlled through this class.
First pull the singleton
$session = Session::singleton();
Now setting and getting variables is simple:
$session->foo = 'bar';
echo $session->foo; // echoes bar
The Session class is using overloading. So _set and _get are controlling the setting and getting. You can also use isset and unset like so:
if (isset($session->foo)) {
echo 'Foo is here!';
}
unset($session->foo);
If a session variable is not set (or unset) and get is called on it an exception will be thrown.