PHP Annotations

Basically, think of docblocks.

The idea behind them originally was to provide documentation on code. E.g. what the parameters of a method were, etc. See these slides for an overview

However, PHP Annotations take this a bit further by letting you inject behaviour. E.g. you can use these docblock statements to change the functionality of the class (i.e. injecting behaviour) which can promote decoupling. E.g. see Symfony uses PHP Annotations for Routing and Doctrine uses PHP Annotations for metadata.

Take a look at these articles / slides:

An overview: http://www.slideshare.net/rdohms/annotations-in-php-they-exist

and a rather interesting counter argument to using them: https://r.je/php-annotations-are-an-abomination.html 

 

Leave a Reply

Your email address will not be published. Required fields are marked *