 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Jake Bell: PHP Annotations Are a Horrible Idea
by Chris Cornutt October 18, 2012 @ 09:45:56
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.
voice your opinion now!
annotations code comments opinion doctrine symfony
Karsten Deubert's Blog: Zend_MVC, Controller Plugins and Annotations
by Chris Cornutt November 28, 2011 @ 12:02:50
Karsten Deubert has a recent post to his blog looking at annotations in Zend Framework applications to enhance functionality already in the framework.
Recently I had the idea to influence Controller Actions with annotations but discarded it with thoughts like "In PHP I will have to use reflection and some black magic to get this working which will have insane performance hits for my applications"... until I set everything up to see that it costs just 1-2ms in average per request without any form of caching.
He includes a few bits of code to show a simple annotation example (setting a layout) and the controller plugin that performs the translation. In his case, it's hard-coded to look for the "@layout" annotation in the docblock comment, but it'd be relatively trivial to extend it to a more full-featured version.
voice your opinion now!
zendframework mvc controller annotations docblock comment plugin
Rafael Dohms' Blog: Filtering objects using annotations
by Chris Cornutt August 12, 2011 @ 10:04:37
Rafael Dohms has an interesting new post to his site today looking at a library he's developed (inspired by the Symfony Validation library) to help filtering values with rules defined in annotations.
PHP does not have native Annotations support, however many projects have been using doc blocks to add value and semantics to code, like PHPUnit, Doctrine and Symfony. The Doctrine did a really good job in making available a Annotation parser kit, which allows you to bring the power of annotations into you own project. This opens up a few possibilities.
He shows the current use of the Validation library with a sample check of a $name variable for "not blank". His tool, DMS, extends this functionality and gives you access to both custom filtering methods and standard PHP functions to filter the resulting variable value. He includes an example showing two variables with filters StripTags, StripNewlines and Trim as well as the code to execute the filtering. You can get the library either ready to integrate with Symfony/Doctrine or as a standalone tool.
voice your opinion now!
filtering symfony annotations validation library
Symfony Blog: Symfony2 Annotations gets better
by Chris Cornutt May 23, 2011 @ 11:08:53
Fabien Potencier has posted another in his "getting better" series looking at the features that are included in the Symfony2 framework. In this new post he talks about the improvement annotation support.
Later today, I will release Symfony2 beta2. But first, I wanted to talk about a big change that landed into master yesterday. As you might know, Symfony2 uses annotations for Doctrine mapping information and validation configuration. Of course, it is entirely optional, and the same can be done with XML, YAML, or even PHP. But using annotations is convenient and allows you to define everything in the same file.
Two new bundles were added, SensioFrameworkExtraBundle and JMSSecurityExtraBundle, that let you use annotations in the controller for configuration. Examples of this new feature are included in the post giving the configuration settings a more "native" feel.
voice your opinion now!
annotations native controller configuration
Gonzalo Ayuso's Blog: Function decorators in PHP with PHPDoc and Annotations
by Chris Cornutt February 01, 2011 @ 13:13:04
Gonzalo Ayuso has a new post to his blog looking at some of the recent work he's done with PHPDoc and annotations to create "function decorators" in his code.
The idea is to solve the same problem I had when I wrote the previous article. I want to protect the execution of certain functions in a class to only being executed if the user is logged on. [...] The solution with interfaces is clean and simple (no extra libraries need and no reflection need too). The problem is that I can use it only for all the functions of the class.
He gives an example class with four different methods (one with annotations) and his annotation parsing class that runs the predispatch and postdispatch methods based on those annotations. He also shows another examples using an abstract class.
voice your opinion now!
annotations decorator phpdocumentor tutorial
PHPImpact Blog: Using Annotations in PHP
by Chris Cornutt July 22, 2008 @ 07:55:04
On the PHP::Impact blog today there's a new post showing how to use annotations in your application's code that can be used by the Addendum library.
Annotations provide data about a program that is not part of the program itself. They have no direct effect on the operation of the code they annotate. In PHP, annotations can only be read reflectively at run time.
They allow you to document, with meta-data, information about the classes, methods and variables inside the script. They show three of the annotation types - a marker, a single-value and a multi-value.
voice your opinion now!
annotations addendum library marker singlevalue multivalue
|
Community Events
Don't see your event here? Let us know!
|