Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #2340
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Preserving an object |
| Date | 2011-06-25 08:02 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <iu4iok$vsf$1@dont-email.me> (permalink) |
| References | <fac5cb7c-2af6-4468-85ac-57067de9b2ca@q15g2000yqk.googlegroups.com> |
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@attglobal.net ==================
Back to comp.lang.php | Previous | Next — Previous in thread | Find similar | Unroll thread
Preserving an object bruceaj <bruceaj@bellsouth.net> - 2011-06-24 19:45 -0700
Re: Preserving an object The Natural Philosopher <tnp@invalid.invalid> - 2011-06-25 09:27 +0100
Re: Preserving an object Jivanmukta <jivanmukta@poczta.onet.pl> - 2011-06-25 04:06 -0700
Re: Preserving an object Jerry Stuckle <jstucklex@attglobal.net> - 2011-06-25 08:08 -0400
Re: Preserving an object bruceaj <bruceaj@bellsouth.net> - 2011-06-25 06:37 -0700
Re: Preserving an object Jerry Stuckle <jstucklex@attglobal.net> - 2011-06-25 13:10 -0400
Re: Preserving an object The Natural Philosopher <tnp@invalid.invalid> - 2011-06-26 04:18 +0100
Re: Preserving an object Jerry Stuckle <jstucklex@attglobal.net> - 2011-06-25 08:02 -0400
csiph-web