Gossamer Forum
Home : Products : Gossamer Links : PHP Front End :

Help with class and object errors anyone?

Quote Reply
Help with class and object errors anyone?
Hello!

Can anyone help me out with this small session class I'm playing with. The below class is included into a file and then called with...

$SN = new Session;
$SN->start_session();

Code:
<?php
class Session {

function Session () {
$this->session_name = 'sessi0n';
$this->session_data = array();
$this->session_user_id = 'test';
}

function start_session () {
global $DB ;

# If we don't already have an open session via cookie
if (! $_COOKIE["$this->session_name"] ) {

$this->session_id = md5( microtime() );
$this->session_date = time() ;

$session = get_object_vars($this);
$info = var_export($session, true);

$ret = $DB->insert("Sessions", $info );

}
}
}
?>


When I run the above with the line "$ret = $DB->insert("Sessions", $info );" commented OUT it gives the following error notice in my log file:

[error] PHP Notice: Undefined index: sessi0n in /path/to/session.class.php on line XX (referring to $_COOKIE["$this->session_name"]). Do you know how to fix this error?

If I uncomment the line "$ret = $DB->insert("Sessions", $info );" it also returns the following error...

[Sun Nov 6 11:23:58 2005] [error] PHP Fatal error: Call to a member function on a non-object in /path/to/session.class.php on line XX referring to "$ret = $DB->insert("Sessions", $info );" - which I assume means it doesn't know about the $DB object that I'm trying to use. That DB object was created just before the session object so it does already exist.

Can anyone help?

Thanks,

Regan.

Last edited by:

ryel01: Nov 5, 2005, 2:30 PM
Subject Author Views Date
Thread Help with class and object errors anyone? ryel01 7243 Nov 5, 2005, 2:30 PM
Thread Re: [ryel01] Help with class and object errors anyone?
Hargreaves 7350 Nov 5, 2005, 3:42 PM
Thread Re: [Hargreaves] Help with class and object errors anyone?
ryel01 7119 Nov 5, 2005, 5:55 PM
Post Re: [ryel01] Help with class and object errors anyone?
ryel01 7191 Nov 5, 2005, 7:52 PM