469,625 Members | 1,099 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,625 developers. It's quick & easy.

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

dlite922
1,584 Expert 1GB
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
3 2261
dlite922
1,584 Expert 1GB
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
5,821 Expert 4TB
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
1,584 Expert 1GB
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.

Similar topics

5 posts views Thread by ChrisB | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.