PHPackages                             huangdijia/constants - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. huangdijia/constants

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

huangdijia/constants
====================

A constants component for PHP.

v1.0.0(2y ago)511MITPHPPHP &gt;=7.1

Since Dec 22Pushed 2y ago1 watchersCompare

[ Source](https://github.com/huangdijia/php-constants)[ Packagist](https://packagist.org/packages/huangdijia/constants)[ RSS](/packages/huangdijia-constants/feed)WikiDiscussions main Synced 6d ago

READMEChangelog (2)Dependencies (3)Versions (7)Used By (0)

PHP Constants
=============

[](#php-constants)

[![Latest Test](https://github.com/huangdijia/php-constants/workflows/tests/badge.svg)](https://github.com/huangdijia/php-constants/actions)[![Latest Stable Version](https://camo.githubusercontent.com/081e7b2fc6315eba89b6da2b5c694db5fa91c9f794e1d229d09f504f9ed951a3/68747470733a2f2f706f7365722e707567782e6f72672f6875616e6764696a69612f636f6e7374616e74732f76657273696f6e2e706e67)](https://packagist.org/packages/huangdijia/constants)[![Total Downloads](https://camo.githubusercontent.com/6b2e1d295836e9e604aad6c3bb8d9ea17913e20ea7f107312b7440d938f897d8/68747470733a2f2f706f7365722e707567782e6f72672f6875616e6764696a69612f636f6e7374616e74732f642f746f74616c2e706e67)](https://packagist.org/packages/huangdijia/constants)[![GitHub license](https://camo.githubusercontent.com/4cab27c8234a482a06c599a3b26ecdb50ad75dfaa53393720a004b713dbe048e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6875616e6764696a69612f7068702d636f6e7374616e7473)](https://github.com/huangdijia/php-constants)

A constants component for PHP.

Installation
------------

[](#installation)

```
composer require huangdijia/constants
```

Usage
-----

[](#usage)

- Before

```
class ErrorCode
{
    const NOT_FOUND = 404;
    const SERVER_ERROR = 500;

    public static $errors = [
        self::NOT_FOUND => 'Not Found',
        self::SERVER_ERROR => 'Server Error',
    ];

    public static function getMessage($code)
    {
        return self::$errors[$code] ?? '';
    }
}
```

- Now

```
namespace App\Constants;

use Huangdijia\Constants\AbstractConstants;

/**
 * @method static string getMessage(string $code)
 * @method static string getMessageCn(string $code)
 * @method static string getMessageEn(string $code)
 */
class ErrorCode extends AbstractConstants
{
    /**
     * @Message("%s not found!")
     */
    const NOT_FOUND = 404;

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

    /**
     * @MessageCn("成功")
     * @MessageEn("Success")
     */
    const OK = 1;

    /**
     * @MessageCn("失败")
     * @MessageEn("Failure")
     */
    const FAILURE = 0;
}

var_dump(ErrorCode::getMessage(ErrorCode::SERVER_ERROR)); // Server Error
var_dump(ErrorCode::getMessage(ErrorCode::NOT_FOUND, '/api')); // /api not found!
var_dump(ErrorCode::getMessageCn(ErrorCode::OK)); // 成功
var_dump(ErrorCode::getMessageEn(ErrorCode::OK)); // Success
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~191 days

Recently: every ~239 days

Total

6

Last Release

1016d ago

Major Versions

v0.1.3 → v1.0.02023-08-06

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8337659?v=4)[Deeka Wong](/maintainers/huangdijia)[@huangdijia](https://github.com/huangdijia)

---

Top Contributors

[![huangdijia](https://avatars.githubusercontent.com/u/8337659?v=4)](https://github.com/huangdijia "huangdijia (4 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/huangdijia-constants/health.svg)

```
[![Health](https://phpackages.com/badges/huangdijia-constants/health.svg)](https://phpackages.com/packages/huangdijia-constants)
```

###  Alternatives

[freshbitsweb/laratables

Ajax support of DataTables for Laravel

4871.1M3](/packages/freshbitsweb-laratables)[ahand/mobileesp

Since 2008, MobileESP provides web site developers an easy-to-use and lightweight API for detecting whether visitors are using a mobile device, and if so, what kind. The APIs provide simple boolean results ('true' or 'false') for identifying individual device categories (such as iPhone, BlackBerry, Android, and Windows Mobile), device capabilities (e.g., J2ME), and broad classes of devices, such as 'iPhone Tier' (iPhone/Android/Tizen) or 'Tablet Tier.' APIs are available in PHP, JavaScript, Java, C#, Ruby Python, and more.

174491.4k7](/packages/ahand-mobileesp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
