PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

Jake Bell: PHP Annotations Are a Horrible Idea

Note: This article was originally published at PHPDeveloper on 19 April 1556.
PHPDeveloper

In his latest post Jake Bell talks about why he thinks annotations in PHP are a bad idea (not the concept of them, but how developers are currently using them. He's in favor of officil support though).

Both the Symfony 2 and Doctrine 2 libraries and components make liberal use of what have come to be called annotations - special code comments, usually prefixed with an @ that are actually interpreted by the application and affect its functionality. [...] This trend needs to die.

He points out that the use of code comments like this isn't a good practice and applications should never have to rely on them for functionality. He mentions issues with syntax/language functionality (can't use "php -l" on them, can't var_dump an annotation) and that it makes it more difficult to read and interpret the code. He includes an example from Ruby of an alternative and a possible solution in PHP involving a static "mapping" variable.