Fwd: Re: Class variable value lost

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



What I have done is declared one User class in a separate file and created
its object there only. After this included this file in all other file which
are using its object. So the object is creating only once and included in
every other file only once. Now when I over write its variable it value get
lost when I send the user in other file.

The confusion is if I have created only one object of a class and used the
same object through out the site how its value can get lost and I think this
is a separate issue than setting $_SESSION variables.





---------- Forwarded message ----------
From: Ashley Sheridan <ash@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, Sep 9, 2009 at 9:14 PM
Subject: Re:  Re: Class variable value lost
To: Shawn McKenzie <nospam@xxxxxxxxxxxxx>
Cc: Sumit Sharma <sumitphp5@xxxxxxxxx>, PHP General Mailing List <
php-general@xxxxxxxxxxxxx>


On Wed, 2009-09-09 at 10:36 -0500, Shawn McKenzie wrote:
> Sumit Sharma wrote:
> > Hi,
> >
> > I have developed a listing site which is totally class based. Now when
it
> > authenticates a user login and set appropriate class variables to true
and
> > set user info in user class variables, value of all the set variables
are
> > lost when I forward the user to members page. When I check the the value
on
> > other page it is set to the default value of the class. Please help.
> >
> >
> > Regard,
> >    Sumit
> >
>
> You needs to pass the object to the next page.  Look into sessions.
>
> --
> Thanks!
> -Shawn
> http://www.spidean.com
>
The object only exists for that instance of the script, so when the user
navigates to the next page, the object is freed up from the memory.
There are a couple of ways you could get round this:

     * don't navigate away from the page, and use AJAX calls to update
       parts of the page for the user (bad imho, as it relies on
       Javascript)
     * use sessions like Shawn recommended

If you use sessions, you can store the objects themselves as variables
into the session. You should be careful with this, as you may not want
too many sessions open with large objects in them as, depending on your
server setup, sessions could last quite a while, and there may also be a
limit on the amount of memory reserved for sessions.

Thanks,
Ash
http://www.ashleysheridan.co.uk

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux