Re: Saving a class instance in a session variable
- From: Jim Cooper <jwcnmr@xxxxxxxxx>
- Date: Mon, 2 Mar 2009 07:01:43 -0800 (PST)
including class instance: yes, see include in the example code
Autostart is off.
No, I am not saving any file handles. A file is opened, rad, and
closed within the constructor, but it is local within the constructor.
On Mar 2, 6:47 am, Jerry Stuckle <jstuck...@xxxxxxxxxxxxx> wrote:
Jim Cooper wrote:
I wrote a simple PHP script to create a new instance of a class (which
reads in a file of state names) if the $_GET command is "init"
session_start();
@include('StateList.php');
$comd=$_GET['nexturl'];
if($comd=="init") {
$st = new StateList("../data/statestxt.txt");
$_SESSION['statefile'] = $st;
}
It saves an instance of this class in a session variable.
Then, later when the user presses a key, it again calls this script
with the command "getState" and tries to fetch the class instance from
the $_SESSION array.
f($comd =="getstate") {
$st= $_SESSION['statefile'];
phplog("size=".$st->getSize());
}
The $st->getSize() is never executed and I am unable to call any
methods on this class.
However if I seriialize it and dump it out to a log, the class seems
to be correct:
phplog("st=".serialize($st));
The phplog function just appends to a file.
What might I be doing wrong? Surely I should be able to execute
methods on this
class stored as a session variable?
A couple of things, Jim,
First of all, are you including the class definition before you start
the session? Are you sure your session is not auto started (see
phpinfo()). Either of these can cause problems loading objects from the
session.
Less likely byt possible - are you saving any resource id's (i.e. file
handles, etc.) in your object? Resource id's generally are not
available across page loads.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@xxxxxxxxxxxxx
==================
.
- Follow-Ups:
- Re: Saving a class instance in a session variable
- From: Jerry Stuckle
- Re: Saving a class instance in a session variable
- From: J.O. Aho
- Re: Saving a class instance in a session variable
- References:
- Saving a class instance in a session variable
- From: Jim Cooper
- Re: Saving a class instance in a session variable
- From: Jerry Stuckle
- Saving a class instance in a session variable
- Prev by Date: Re: Saving a class instance in a session variable
- Next by Date: Re: Saving a class instance in a session variable
- Previous by thread: Re: Saving a class instance in a session variable
- Next by thread: Re: Saving a class instance in a session variable
- Index(es):
Relevant Pages
|