getConstants(); self::$valueToConstantNameMap = array_flip($constantNameToValueMap); } if (isset(self::$valueToConstantNameMap[$value])) { return self::$valueToConstantNameMap[$value]; } return null; } /** * @param string|int $value */ public static function getConstantNameByValue($value): string { $constantName = static::findConstantNameByValue($value); if ($constantName === null) { throw new \InvalidArgumentException(sprintf('"%s" does not have constant with value "%s".', static::class, $value)); } return $constantName; } }