hyperf icon indicating copy to clipboard operation
hyperf copied to clipboard

枚举类能用属性声明吗

Open zhangyu19851112 opened this issue 2 years ago • 3 comments
trafficstars

文档的写法

/**

  • @Message("Server Error!") */ public const SERVER_ERROR = 500;

可以这样使用吗? #[Message("Server Error!")] public const SERVER_ERROR = 500;

zhangyu19851112 avatar May 08 '23 02:05 zhangyu19851112

看了一下源码,不可以。

Hyperf\Constants\AnnotationReader::getAnnotations()

lazychanger avatar May 08 '23 07:05 lazychanger

其实也不是不可以的,但是因为这样,就必须要专门定义对应的注解了。。可能会在 3.1 及以后版本做兼容

limingxinleo avatar May 08 '23 15:05 limingxinleo

其实也不是不可以的,但是因为这样,就必须要专门定义对应的注解了。。可能会在 3.1 及以后版本做兼容

我来安利一下一个枚举类的注解应用:https://github.com/lishuncoder/enums

lishuncoder avatar May 10 '23 13:05 lishuncoder