My first line in my script I have:
$db = new db_class();
This is just an example to start the db object. Then I have:
class main {
function init() {
$this->session_start();
}
protected function session_start() {
$sh = new session_handler();
session_set_save_handler(
array (& $sh, 'open'),
array (& $sh, 'close'),
array (& $sh, 'read'),
array (& $sh, 'write'),
array (& $sh, 'destroy'),
array (& $sh, 'gc')
);
}
}
All of the problems are in the in session_handler
class. This code:
public function write($id, $data) {
global $db;
var_dump($db); //returns NULL
}
says that $db
is NULL
instead of an instance of db_class
.
Note, db_class
objects work except when calling the write()
method:
class main {
function init() {
global $db;
var_dump($db); //returns the db object correctly
$this->session_start();
}
protected function session_start() {
$sh = new session_handler();
session_set_save_handler(
array (& $sh, 'open'),
array (& $sh, 'close'),
array (& $sh, 'read'),
array (& $sh, 'write'),
array (& $sh, 'destroy'),
array (& $sh, 'gc')
);
}
}