# Annotation Annotation is a very powerful feature of Hyperf that can be used to reduce a lot of configuration in the form of annotation and to implement many very convenient features. ## Concept ### What is annotation and what is comment? Before interpreting the annotation, we need to define the difference between `annotation` and `comment`: - Comment: For the programmer to see, help understand the code, explain and explain the code. - Annotation: For the system or application to see, the definition of metadata. There is no effect when used alone, it needs to be used in conjunction with the application to use its metadata to works. ### How it parse ? Hyperf uses the [doctrine/annotations](https://github.com/doctrine/annotations) package to parse the annotations in the code. The annotations must be written in the standard comment block below to be parsed correctly. Other formats cannot correctly parsed. Example: ```php /** * @AnnotationClass() */ ``` The syntax of writing `@AnnotationClass()` in the standard comment block indicates that the object (class, class method, class attribute) of the current comment block is annotated, and `AnnotationClass` corresponds to an `annotation class`. The class name of the class can be written in the namespace of the whole class, or just the class name, but the annotation class needs to be in the current class `use` to ensure that the correct annotation class can be found according to the namespace. ### How is works ? We have said that annotations are just metadata definitions that need to work with the application to work. In Hyperf, the data in the annotations are collected into the `Hyperf\Di\Annotation\AnnotationCollector` class for usage of application, depending on your demand, you can also collect the data to your custom classes and then read and utilize the collected annotation metadata in the place where the annotations themselves are expected to work to achieve the desired functional implementation. ### Ignore some annotations In some cases we may wish to ignore certain annotations. For example, when we access some tools that automatically generate documents, many tools use annotations to define the relevant structural content of the document. These annotations may not be in line with how Hyperf is used, we can set the concern to be ignored by `config/autoload/annotations.php`. ```php return [ 'scan' => [ // Annotations in the ignore_annotations array will be ignored by the annotation scanner 'ignore_annotations' => [ 'mixin', ], ], ]; ``` ## Usage of Annotation There are three apply types of annotation, `class`, `method of class` and `property of class`. ### Use class level annotation Class level annotation definitions are in the comment block above the `class` keyword. For example, the commonly used `@Controller` and `@AutoController` are examples of the use of class level annotation. The following code example is an example of correctly using class level annotation, indicating The `@ClassAnnotation` annotation is applied to the `Foo` class. - PHP < 8.0 ```php = 8.0 ```php = 8.0 ```php = 8.0 ```php Notice that `@Annotation` and `@Target` annotations in Annotation Class are Global Annotation,no need fo `use` keyword to define the namespace. `@Target` has the following parameters: - `METHOD` annotation means allows define on class methods - `PROPERTY` annotation means allows define on class properties - `CLASS` annotation means allows define on class - `ALL` annotation means allows define in all scopes - PHP >= 8.0 ```php