Re: Saving a class instance in a session variable



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

.



Relevant Pages

  • Re: Saving DataTable to session vs saving a Custom object.
    ... I don't think the session you refer to will actually result in any ... The biggest overhead you'd see in memory usage would be the ... > DataTable to session vs saving a custom object of the same data. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Default setting for Saving attachments
    ... You can change the setting for that session by saving a whole message to ... "Lynn W" wrote in message ... > save any pics there which is what I am usually saving, ... > could change it rather than having to scroll to find the usual folder to ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: Vista Shutdown
    ... And why do you think it is not saving the settings. ... Because he changed them during a session. ... Duh ...
    (microsoft.public.windows.vista.general)
  • Re: Issue with threading?
    ... then remove from the Session once it has been used. ... Instead of saving the info to a cookie, ... impossible given that they are three separate apps? ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Get internal variable name as atom
    ... My goal is to reuse the same Class object for all backtracking steps. ... internal session handling. ... would fail since they use the same java class instance (and thus the same ...
    (comp.lang.prolog)