FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Preserving an object
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Preserving an object [message #174664 is a reply to message #174661] Sat, 25 June 2011 12:02 Go to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 6/24/2011 10:45 PM, bruceaj wrote:
> I am creating an object in my "index.php". I want to use this object
> in many of my php pages. How can I preserve this object so other pages
> can use it and I don't have to recreate it??
>
> Thanks...
>
> Bruce

It's difficult because PHP does not handle serialization of objects very
well.

The correct way would be to store it in the $_SESSION. However, you
have to be careful that the object doesn't save any external resources
such as database links, which will not be valid when it is reloaded.

Additionally, when your page terminates, the PHP calls the object's
destructor, but does not call the object's constructor when it is read
back into storage. This means the constructor will be called once for
the object, but the destructor called many times.

One other thing - the $_SESSION isn't real efficient for larger data
structures; I wouldn't recommend storing large objects in it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: library using $_SESSION
Next Topic: PHP Function to translate a URL into the URL that it is redirected to
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 12:46:03 GMT 2024

Total time taken to generate the page: 0.04690 seconds