The annotation is very simple to use. Just like using a class, first introduce the class with the use keyword, then use the annotation.

 use Swoft\Http\Server\Annotation\Mapping\Controller; 

 * 类注释
 * @since 2.0
 * @Controller("a")
class A
  • Line 1 introduces an annotation class, like a normal class
  • Line 8 uses annotations, format @类名 , and some class names will have parameters, such as "a" this annotation.


Why does PHP's normal comments have functionality? In fact, it's very simple. Get all the annotations in the class via PHP reflection ( ), followed by the PHP component ( Annotations make it special.