# Enum class When you need to define error codes and error messages, the following methods may be used, ```php 'Server Error', self::PARAMS_INVALID => 'Illegal parameter' ]; } $message = ErrorCode::messages[ErrorCode::SERVER_ERROR] ?? 'unknown mistake'; ``` But this implementation method is not friendly. Whenever you want to query the error code and the corresponding error information, you have to search the current `Class` twice, so the framework provides an annotation-based enumeration class. ## Install ``` composer require hyperf/constants ``` ## Use ### Define the enum class An enumeration class can be generated quickly with the `gen:constant` command. ```bash php bin/hyperf.php gen:constant ErrorCode ``` ```php This feature is only available on v1.1.13 and later To enable the [hyperf/constants](https://github.com/hyperf/constants) component to support internationalization, the [hyperf/translation](https://github.com/hyperf/translation) component must be installed and configured Good language files, as follows: ``` composer require hyperf/translation ``` For related configuration, see [Internationalization](en/translation.md) ```php 'Params :param is invalid.', ]; use Hyperf\Constants\AbstractConstants; use Hyperf\Constants\Annotation\Constants; #[Constants] class ErrorCode extends AbstractConstants { /** * @Message("params.invalid") */ const PARAMS_INVALID = 1000; } $message = ErrorCode::getMessage(ErrorCode::SERVER_ERROR, ['param' => 'user_id']); ```