By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,292 Members | 1,615 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,292 IT Pros & Developers. It's quick & easy.

Save session to DB "Using $this when not in object context"

dlite922
Expert 100+
P: 1,584
Hey guys,

My brains asleep and I don't know what's wrong with my session class.

I'm over riding session with sesstion_set_save_handler() in a class;

When in my member functions (open, close, read) I use "$this" I get the error "Using $this when not in object context".

Here's my constructor:

[PHP]

/**
* @desc Constructor
*/
function __construct
(
)
{

session_set_save_handler(array(&$this, 'open'),
array(&$this, 'close'),
array(&$this, 'read'),
array(&$this, 'write'),
array(&$this, 'destroy'),
array(&$this, 'gc'));
try
{
$this->sessionVO = new SessionVO();
$this->sessionDAO = new DAO($this->sessionVO);

$this->maxLifeTime = get_cfg_var("session.gc_maxlifetime"); // or set it to something else.
}
catch (Exception $e)
{
die($e->getMessage());
}

}

[/PHP]

here's my open method


[PHP]

/**
* @desc Opens the session
* @return bool
*/
public static function open
(
)
{
$dbLink = $this->sessionDAO->getDBLink();
return !is_null($dbLink);
}

[/PHP]

My data members are private ($sessionVO and $sessionDAO)


pbmods...ronverdonk...anybody? Any suggestion is appreciated.

Yours,

Dan
May 31 '08 #1
Share this Question
Share on Google+
3 Replies


dlite922
Expert 100+
P: 1,584
Nevermind guys.

it fixed itself.

after commenting out all lines and emptying the functions one by one (it would just throw the error on the next function that was using it)

Then uncommented open() method which uses $this , but the error wouldn't point there anymore.

I uncommented them each and fixed other errors not related to this as they came up.

I really can't explain it, but meh...whatever.
Jun 1 '08 #2

pbmods
Expert 5K+
P: 5,821
Heya, Dan.

You made open(), etc. static methods, which can't use $this.

[EDIT: Incidentally, PHP automatically hands off e.g., session max age to certain methods. For an example, see this article.]
Jun 2 '08 #3

dlite922
Expert 100+
P: 1,584
Heya, Dan.

You made open(), etc. static methods, which can't use $this.

[EDIT: Incidentally, PHP automatically hands off e.g., session max age to certain methods. For an example, see this article.]
Yes sorry haven't been keeping this updated. Turns out I did that and still couldn't. Yes weird, but I'm just now declaring the new objects instead of using data members.

Just for kicks, i'll go back and just make them public functions, but I'm 100% i did this and didn't work.

Aww, Did i inspire you to write that article. I feel loved, man.

I'll read it for sure.

see ya,


Dan
Jun 2 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.