public static function getConst ( ) : array $objClass = new \ ReflectionClass ( get_called_class ( ) ) ; return $objClass -> getConstants ( ) ; * 获取所有常量名 * @return array public static function getConstantsKeys ( ) : array return array_keys ( self :: getConst ( ) ) ; * 获取所有常量值 * @return array public static function getConstantsValues ( ) : array return array_values ( self :: getConst ( ) ) ; * 获取常量注释 * @param string $key 常量名 * @return string public static function getDescription ( string $key ) : string return preg_replace ( '#[\*\s]*(^/|/$)[\*\s]*#' , '' , ( new ReflectionClassConstant ( static :: class , $key ) ) -> getDocComment ( ) ) ; * 获取常量名和注释列表 * @return array public static function getKeyDescription ( ) : array $keys = self :: getConstantsKeys ( ) ; $result = [ ] ; foreach ( $keys as $key => $key_name ) { $result [ $key_name ] = self :: getDescription ( $key_name ) ; return $result ; * 获取常量值和注释列表 * @return array public static function getValueDescription ( ) : array $const = self :: getConst ( ) ; $result = [ ] ; foreach ( $const as $key => $value ) { $result [ $value ] = self :: getDescription ( $key ) ; return $result ;

子类代码如下:

namespace app \ common \ enums ; class PacketStatus extends BaseEnum /** 未领取 */ const UNCLAIMED = 0 ; /** 未发放 */ const READY = 1 ; /** 处理中 */ const PROCESSING = 2 ; /** 发放成功 */ const SUCCESS = 3 ; /** 发放失败 */ const FAIL = 4 ;
获取所有常量
// 获取所有常量
PacketStatus::getConst()
// 返回结果:
array(5) {
  ["UNCLAIMED"] => int(0)
  ["READY"] => int(1)
  ["PROCESSING"] => int(2)
  ["SUCCESS"] => int(3)
  ["FAIL"] => int(4)
获取所有常量名
// 获取所有常量名
PacketStatus::getConstantsKeys()
// 返回结果:
array(5) {
  [0] => string(9) "UNCLAIMED"
  [1] => string(5) "READY"
  [2] => string(10) "PROCESSING"
  [3] => string(7) "SUCCESS"
  [4] => string(4) "FAIL"
获取所有常量值
// 获取所有常量值
PacketStatus::getConstantsValues()
// 返回结果:
array(5) {
  [0] => int(0)
  [1] => int(1)
  [2] => int(2)
  [3] => int(3)
  [4] => int(4)
获取常量名和注释列表
// 获取常量值和注释列表
PacketStatus::getKeyDescription()
// 返回结果:
array(5) {
  ["UNCLAIMED"] => string(9) "未领取"
  ["READY"] => string(9) "未发放"
  ["PROCESSING"] => string(9) "处理中"
  ["SUCCESS"] => string(12) "发放成功"
  ["FAIL"] => string(12) "发放失败"
获取常量值和注释列表
// 获取常量值和注释列表
PacketStatus::getValueDescription()
// 返回结果:
array(5) {
  [0] => string(9) "未领取"
  [1] => string(9) "未发放"
  [2] => string(9) "处理中"
  [3] => string(12) "发放成功"
  [4] => string(12) "发放失败"
注解功能使得代码中的声明部分都可以添加结构化、机器可读的元数据, 注解的目标可以是类、方法、函数、参数、属性、类常量。
通过 反射API可在运行时获取注解所定义的元数据。 因此注解可以成为直接嵌入代码的配置式语言
说人话就是,注解实现的原理是反射,通过动态代理模式可以直接嵌入代码的配置,注解可以作用在类,方法,函数,参数,属性和常量上面。
使用注解可以在实现功能、使用功能相互解耦
在php中,注解的语法是总是以#[开头,...
				
php 魔术常量详解 实例: class MoShu{ public function moshu() { echo '当前类:' . __CLASS__ . ; echo '当前方法:' . __FUNCTION__ . ; echo '当前文件中所在的行数:' . __LINE__ . ; ...
在Java中,枚举类型是一种特殊的类,它定义了一组有限的常量值。枚举常量名称通常是大写字母,但是它们也可以有一个与之对应的字符串值。如果一个枚举常量有一个字符串值,那么可以通过调用枚举常量的name()方法获取枚举常量名称,或者调用枚举常量的toString()方法获取枚举常量的字符串值。 下面是一个示例代码,演示了如何获取枚举常量的字符串值: enum Color { RED("红色"), GREEN("绿色"), BLUE("蓝色"); private String value; private Color(String value) { this.value = value; public String getValue() { return value; public class Main { public static void main(String[] args) { Color color = Color.GREEN; String name = color.name(); String value = color.getValue(); String str = color.toString(); System.out.println(name); // 输出:GREEN System.out.println(value); // 输出:绿色 System.out.println(str); // 输出:绿色 在这个例子中,我们首先定义了一个枚举类型Color,包含三个常量:RED、GREEN和BLUE。每个枚举常量都有一个与之对应的字符串值,存储在枚举常量的value属性中。Color类还定义了一个getValue()方法,用于获取枚举常量的字符串值。 在main()方法中,我们定义了一个Color类型的变量color,并将其赋值为枚举常量GREEN。然后,我们分别调用color的name()方法、getValue()方法和toString()方法,获取枚举常量名称、字符串值和toString()方法返回的字符串值。最后,我们输出了这三个值,分别为GREEN、绿色和绿色。 需要注意的是,如果一个枚举常量没有对应的字符串值,那么调用其getValue()方法会返回null,调用其toString()方法会返回枚举常量名称
网站请求异常502 php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream PHP 实现防抖功能(防重复请求) Linux+Nginx+PHP并发参数优化配置记录