Serialization pitfalls

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
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Serialization pitfalls

Post by greyhoundcode »

I love the idea of serializing objects, storing them on a database, then bringing them back to life. It seems a very convenient way, for instance, of storing application settings within an object, particularly as opposed to .ini files or XML: but are there performance or other issues to be wary of with this approach?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Serialization pitfalls

Post by Weirdan »

One obvious problem: by storing a complex structure in a single field you're violating 1NF and prevent yourself from querying on particular values in that complex structure.
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Re: Serialization pitfalls

Post by greyhoundcode »

I see what you're saying, but in terms of facilitating a persistent object are there any other workable options?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Serialization pitfalls

Post by Weirdan »

For arbitrary objects - no, not really (short of using document-oriented databases like CouchDB or MongoDB). However if you have a fixed object class you can use any of available ORM solutions to map objects to table rows (in the simplest case).
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Re: Serialization pitfalls

Post by greyhoundcode »

Good advice as always, thanks.
Post Reply