February 19, 2007

I always disliked the way PHP handles Objects. There is no way to assign a type to properties. Validators have to be glued against the fields externally and you can’t just generate a Object-Description (like WSDL) from a object either.

The property unknown gets created automaticly in the object and since gets a invalid value. If you take a look at ActiveRecord in Rails you see how proper types can simplify your life. They also assign the validators directly in the DataObject Classes, because that’s the obvious place where you want to guarantee consistency of your data.

The approach we choose here changes the behaviour of PHP objects:

properties are always initialized with NULL

properties are NOT automaticly declared

properties always have a type

at assigment the type is enforced and converted if possible without loss of data

At the side we win:

WSDL generation

SQL which is automaticly escaped correctly

In Java 1.5.x and later they got annotations and we can use the same in PHP:

Yes, doc-comments. Not only we added documentation to our code (which is always a good thing), we can also use them for the type-definition. With the help of Reflection we can get the DocComments of a property and extract the @var from it.

Similar to the term POJO we call our objects POPO (plain old php objects).