473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 2544
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

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

Similar topics

1
by: lawrence | last post by:
I'm trying to gain a better understanding of javascript by studying examples. I noticed this in an online tutorial. I don't get the use of "this". >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> You might want...
11
by: Florian Loitsch | last post by:
I'm currently writing a JS->Scheme compiler (which, using Bigloo, automatically yields a JS->C, JS->JVM, JS->.NET compiler), and have a question concerning the function-parameters: According to...
7
by: Clint Herron | last post by:
Howdy! I posted this question on CSharpCorner.com, but then realized I should probably post it on a more active newsgroup. This will be my only cross-post. I'm creating a game engine, and...
6
by: Thomas H | last post by:
Hi everyone, I've got a question that's more of a "style" question... Do you guys reference "this" for every object that's inherited from System.Web.UI.Page? For example, when you use the...
5
by: ChrisB | last post by:
Hello: An object that is a field in another object has a constructor that requires a reference to the containing object: // object fields ChildObject childObject = new ChildObject(this); ...
23
by: lwoods | last post by:
I am trying to pass some info to another page on my site. I set "session_start()" in page 1, assign a session variable to a value, then execute a "header('Location: ....')." But on the target...
25
by: samjnaa | last post by:
Please check for sanity and approve for posting at python-dev. In Visual Basic there is the keyword "with" which allows an object- name to be declared as governing the following statements. For...
0
by: Reader | last post by:
On a windows form, there is TableLayoutPane. I 1) Increase size of form 2) Increse size of table 3) Add a row in the table 4) Save I receive exception "Value cannot be null. Parameter name:...
3
by: =?Utf-8?B?U2hhbG9t?= | last post by:
I have installed iis 7 on my win vista home premium Sony Vaio laptop, and then tried executing downloaded sample working asp scripts in the wwwroot directory to try out. The first asp script...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.