Object Persistence
$user = new User($userID);
An oxymoron. If I have the user’s ID, it’s not likely to be a new user, is it? There’s a disconnect between the lifespan of an object and the lifespan of the entity it represents. If I’m not creating a new user, that is, the user I’m dealing with has been instantiated before, then why do I need to create a new object? Why was that object destroyed if the user still exists?
I don’t know much about object persistence. However, I can see a few reasons why it makes sense for objects to outlive fleeting executions of a program (i.e. HTTP requests). It would be nice for database-returned results to be bona fide objects; reinstantiating objects, at least in PHP, is relatively costly, and arguably pointless (pointless except for the fact that there’s no other way :-P ).
I’ll be keeping my eye on things like db40 to see if workable object persistence ever makes its way to PHP land.
A future where SQL and relational databases are arcane tools used primarily by the minders of legacy systems is conceivable. As OO takes over more and more of the software space, and servers get faster and faster, the potential savings in development costs offered by real object persistence will outweigh the speed penalty.
Tags: OOP




