Object Persistence?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chadlong41
Forum Newbie
Posts: 3
Joined: Tue Feb 03, 2009 11:33 am

Object Persistence?

Post by chadlong41 »

Is there object persistence in PHP 5?

I ask because it seems that with all the associated memory overhead with OOP, I am wondering if there is another reason for PHP to go OO besides maintainability.
mickeyunderscore
Forum Contributor
Posts: 129
Joined: Sat Jan 31, 2009 9:00 am
Location: UK

Re: Object Persistence?

Post by mickeyunderscore »

The only way I know of to accomplish object persistence is to serialize them into a cookie, or something else that you can retrieve again on the next request.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Object Persistence?

Post by Christopher »

chadlong41 wrote:Is there object persistence in PHP 5?
You can put them in the session. Just assign to $_SESSION. It will even serialize for you. You can serialize an object and save it to any datasource. Obviously if it has things like file handles and database connection you will need to deal with those. There are wake/sleep methods to do that too.
chadlong41 wrote:I ask because it seems that with all the associated memory overhead with OOP, I am wondering if there is another reason for PHP to go OO besides maintainability.
If you only use OO for maintainability and actually have a problem with memory usage, then you may not want to use OO.
(#10850)
Post Reply