phanalist

E0004: Uppercase Constants

In plain English: Global constants defined with define() and class/interface/trait/enum constants should always be written in ALL_CAPS (uppercase letters separated by underscores).

Why it matters: Following consistent naming conventions makes code instantly recognizable. In PHP, constants do not change their value. By convention, uppercase names tell any developer reading the code: “This value is immutable and global/constant; it is not a regular variable.”

❌ The Bad Example

define('max_retries', 3);

class Config {
    public const timeoutSeconds = 30;
}

✅ The Good Example

define('MAX_RETRIES', 3);

class Config {
    public const TIMEOUT_SECONDS = 30;
}

What the rule checks

When it does not report

How to fix

Configuration

E0004 has no configuration options and is enabled by default.

Junior Engineer’s Rule of Thumb:

Variables start with lowercase or camelCase ($userCount). Constants are always UPPER_CASE_WITH_UNDERSCORES.