Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Jan Kneschke's Blog:
typesafe objects in PHP
Feb 20, 2007 @ 13:29:00

Manfred Weber points out a new blog post from Jan Kneschke concerning the creation of and the idea of typesafe objects in PHP via doc-comments and the Reflection API.

From Jan:

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.

Because of this he's looked into an alternate solution - the typesafe objects. Since, by defauly, PHP's addition of object properties is pretty freeform, making things typesafe is a little difficult. His suggestion, though, uses a combination of comments in the code (declaring what the type of the property should be) and the Reflection API built in to PHP to "look back" at the comments and ensure the type of the property is correct. He even includes examples - a simple one about throwing an error, generating XML this way, and making safe encoded SQL statements.

tagged: typesafe object reflection comment type property typesafe object reflection comment type property

Link:

Jan Kneschke's Blog:
typesafe objects in PHP
Feb 20, 2007 @ 13:29:00

Manfred Weber points out a new blog post from Jan Kneschke concerning the creation of and the idea of typesafe objects in PHP via doc-comments and the Reflection API.

From Jan:

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.

Because of this he's looked into an alternate solution - the typesafe objects. Since, by defauly, PHP's addition of object properties is pretty freeform, making things typesafe is a little difficult. His suggestion, though, uses a combination of comments in the code (declaring what the type of the property should be) and the Reflection API built in to PHP to "look back" at the comments and ensure the type of the property is correct. He even includes examples - a simple one about throwing an error, generating XML this way, and making safe encoded SQL statements.

tagged: typesafe object reflection comment type property typesafe object reflection comment type property

Link:


Trending Topics: