Skip to content

Instantly share code, notes, and snippets.

@jwdunne
Created September 28, 2011 07:04
Show Gist options
  • Save jwdunne/1247199 to your computer and use it in GitHub Desktop.
Save jwdunne/1247199 to your computer and use it in GitHub Desktop.
Namespaced Sessions
<?php
session_start();
/**
* Session Class
*/
class Session {
private $namespace;
public static function init($namespace) {
return new Session($namespace);
}
public function __construct($namespace) {
$this->namespace = $namespace;
}
public function __get($name) {
$key = $this->createKey($name);
if (isset($_SESSION[$key])) {
return $_SESSION[$key];
}
}
public function __isset($name) {
$key = $this->createKey($name);
return isset($_SESSION[$key]);
}
public function __set($name, $value) {
$key = $this->createKey($name);
$_SESSION[$key] = $value;
}
private function createKey($name) {
return $this->namespace.$name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment