I keep getting:
Fatal error: Using $this when not in object context in "classname"
THe problem is that I have been through this class with a fine toothed comb and I cannot find where the erroneous $this is...
Any help would be appreciated!
Here is the code:
class CookieRegistry extends Registry {
private $created;
private $userid;
private $version = 1;
private $td;
private $cookie;
private $cypher = 'blowfish';
private $mode = 'cfb';
private $key = 'privatekey';
private $cookiename = 'blahblah';
private $myversion = '1';
private $expiration = '';
private $warning = '';
private $resettime = '';
private $glue = '|';
private $client;
private $path = '/';
private $domain = 'www.mydomain.com';
private static $instance;
private $values = array();
private $dirty = false;
private $secure = 1;
private function __construct() {
$this->reload();
}
static function instance() {
$this->userid = $_SESSION['user_name'];
$this->client = $_SERVER['REMOTE_ADDR'];
if ( ! self::$instance ) { self::$instance = new self(); }
return self::$instance;
}
function __destruct() {
if ( $this->dirty ) {
$this->save();
}
}
private function reload() {
$values = session_get_cookie_params();
if ( empty( $values ) ) {
return false;
}
if ($this->_unpackage( $values )) {
if ( $this->dirty ) {
$this->values = array_merge( $this->values, $values );
} else {
$this->values = $values;
}
return true;
}
return false;
}
private function save() {
$frozen = $this->_package( serialize( $this->values ));
setcookie( $this->cookiename, $frozen, $this->expiration, $this->path, $this->domain, $this->secure);
$self->dirty = false;
}
protected function get( $key ) {
return $this->values[$key];
}
protected function set( $key, $val ) {
$this->dirty = true;
$this->values[$key] = $val;
}
static function isEmpty() {
return empty( self::instance()->values );
}
static function getDSN() {
return self::instance()->get('dsn');
}
static function setDSN( $dsn ) {
return self::instance()->set('dsn', $dsn);
}
static function getControllerMap( ) {
return self::instance()->get('cmap');
}
static function setControllerMap( ControllerMap $map ) {
return self::instance()->set('cmap', $map);
}
private function _package($data) {
$parts = array($this->myversion, $data, time(), $this->userid, $this->client);
$cookie = implode($this->glue, $parts);
return $this->_encrypt($cookie);
}
private function _unpackage($cookie) {
$buffer = $this->_decrypt($cookie);
list($this->version, $this->values, $this->created, $this->userid, $this->client) = explode($this->glue, $buffer);
if($this->version != $this->myversion || !$this->created || !$this->userid || !$this->client) { return false; } else { return true; }
}
private function _encrypt($plaintext) {
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($this->td), MCRYPT_RAND);
mcrypt_generic_init ($this->td, $this->key, $iv);
$crypttext = mcrypt_generic ($this->td, $plaintext);
mcrypt_generic_deinit ($this->td);
return $iv.$crypttext;
}
private function _decrypt($crypttext) {
$ivsize = mcrypt_get_iv_size($this->cypher, $this->mode);
$iv = substr($crypttext, 0, $ivsize);
$crypttext = substr($crypttext, $ivsize);
mcrypt_generic_init ($this->td, $this->key, $iv);
$plaintext = mdecrypt_generic ($this->td, $crypttext);
mcrypt_generic_deinit ($this->td);
return $plaintext;
}
private function _reissue() {
$this->created = time();
}
}