
The first beta of Doctrine 2, the generic Data Mapper for PHP,
has been released today. Doctrine 2 is one of the few object-relational mappers for PHP which implement the
Data Mapper pattern instead of the
Active Record one; as a result, it is expected to be revolutionary for PHP development as much as Hibernate was for the Java world. For example, Symfony has chosen Doctrine as its default Orm and will follow-up with its second major version, while Zend Framework will provide integration of Doctrine 2 in the form of application resources.
The abstraction of having every object available in memory
The Data Mapper pattern is in general very flexible: you can create domain classes as Plain Old PHP Objects, which do not extend any abstract base class; subsequently a Data Mapper layer abstracts the database as a generic storage. Though, application-specific Data Mappers are generally boring and repetitive to write, while also being prone to errors.
With Doctrine 2, you still produce an object model and, with the aid of mapping metadata in the form of small XML files or annotations, the schema of the related relational database is inferred, while the client code in the rest of the application lives the illusion of an in-memory object graph.
You can largely ignore the database, considering it an implementation detail. The schema can be generated and created from the command line, and there are more than one thousand unit tests to target the different database management systems used as back ends (MySQL, Postgresql, Oracle, Sqlite) to avoid unpleasant surprises. Depending on your vendor of choice, database-specific SQL code will be generated for the creation phase and during querying.
Underlying technology
Doctrine 2 goes to a great extent to avoid introducing unnecessary code for persistence purposes only. The objects' content are accessed and reconstituted via reflection, avoiding the use of getters or initialization methods, while part of the object graph can be substituted by lazy-loading proxies which take the place of real objects by dynamically subclassing them; however performance can be problematic if you over use this feature. Moreover, this first beta of Doctrine 2 is the first to
support constructors with non-optional arguments; objects are recreated via cloning to bypass the constructor call, further extending the metaphor of objects that never leave memory.
If you have already been using Doctrine 2 in its alpha stage, there is a
guide to the upgrade from the alpha 4 version. The
official documentation is also fairly good for a project which is not yet officially stable. If you want to contribute to the codebase instead, the development has been moved on
github and only a fork divides you from producing a useful patch.