Another post about PHP and the topic is once again data persistence. I’m starting to wonder if this is my search for the Holy Grail…
I previously blogged about some differences in the implementations of the Zend Framework and the eZ components. Let it be clear, the Zend Framework’s implementation is also not the most logical one.
Something they have in common is that neither can cope with composite keys. No biggie you’d think until you encounter two entities with a many-to-many relationship. While there are ways to circumvent that problem, I’d rather have it working without trickery.
The real oddity in the Zend Framework comes when you start working with results from database fetches. The persistence starts by defining a PHP class that extends Zend_Db_Table. A fetch from that table results in an object of the Zend_Db_Table_Rowset class. Iterating over that object results in objects of the Zend_Db_Table_Row class. This means that one row from the database is not an instance of the persistent class. The real drawback of that implementation comes when you want to define custom properties on “persistent objects”.
An example of such a custom property: artists and songs. Each artist is an object of the Artist class. Instead of having to load the Song table yourself and query it for all songs of Artist A, it would be a lot handier if you could access all songs by using a property, e.g. $artist->songs.
If you would like to achieve such a thing with the Zend Framework, you have to start implementing your own extended Zend_Db_Table_Row classes and making sure all results are casted to the new type. Not good. Another possibility would be to implement something in the persistent class (the table’s class), but that’s even less logical.
So here I am… once again in search of a good implementation. Looking back at things, the data persistence implementation that ships with eZ publish is not that bad after all. Anyways, I hereby call upon the world to leave a comment if you know of any other data persistence implementations for PHP5.
P.S.: I’ve tried looking at Symfony, but I found its installation to be too cumbersome at the time (not to mention that I couldn’t download a required library). So there’s no need to mention that one.