PHP doesn’t support explicit type definition. This is annoying, especially when doing meta programming. Various libraries including but not limited to Doctrine ORM and the Symfony Validator provide their own type managing system. Another common way to describe type(s) of a property is integrated documentation aka PHPDoc.
The PHP Property Info library extracts various information including the type and documentation from PHP class properties from metadata of popular sources including:
- Setter method with type hint
- PHPDoc’s DocBlock
- Doctrine ORM mapping (annotation, XML, YML or custom format)
Thanks to the visitor pattern, adding support for other metadata source is easy, and Pull Requests are welcome!
As usual, this library is freely available (MIT license) on my GitHub page.
As you maybe know, I’m working on a new way to build hypermedia REST API with Symfony (an experimental release is already available: DunglasJsonLdApiBundle). This bundle will leverage PHP Property Info and the Symfony Serializer Component that will be shipped in Symfony 2.7 to allow powerful deserialization.