Hyperf 使用 @date、@datetime 注释启动都报错 作者: Chuwen 时间: 2021-07-03 分类: PHP Hyperf 使用 @date、@datetime 注释启动都报错 ### 使用 @date 注释 代码如下: ```php * @date: 2021/7/3 12:28 */ public function index(RequestInterface $request, ResponseInterface $response): \Psr\Http\Message\ResponseInterface { return $response->raw($this->help()); } } ``` 报错: ```log #4 /www/wwwroot/NowTool/vendor/hyperf/d in /www/wwwroot/NowTool/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php on line 39 Fatal error: Uncaught Doctrine\Common\Annotations\AnnotationException: [Semantical Error] The annotation "@date" in method App\Controller\V1\Video\DouyinController::index() was never imported. Did you maybe forget to add a "use" statement for this annotation? in /www/wwwroot/NowTool/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php:39 Stack trace: ``` ### 使用 @datetime 注释 又报以下错误: ```log Fatal error: Uncaught Doctrine\Common\Annotations\AnnotationException: [Semantical Error] The class "datetime" is not annotated with @Annotation. Are you sure this class can be used as annotation? If so, then you need to add @Annotation to the _class_ doc comment of "datetime". If it is indeed no annotation, then you need to add @IgnoreAnnotation("datetime") to the _class_ doc comment of method App\Controller\V1\Video\DouyinController::index(). in /www/wwwroot/NowTool/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php:39 Stack trace: ``` > The class "datetime" is not annotated with @Annotation. Are you sure this class can be used as annotation? If so, then you need to add @Annotation to the _class_ doc comment of "datetime". ### 看到以上错误大概需要怎么做了 参照文档的“注解”部分:https://hyperf.wiki/2.1/#/zh-cn/annotation 解决办法就是,添加需要忽略“注解”,配置文件位置 `/config/autoload/annotations.php`: ![](https://cdn.nowtime.cc/2021/07/03/7126507.png) 然后就可以正常启动了 ![](https://cdn.nowtime.cc/2021/07/03/1670611706.png) 标签: PHP, Hyperf