← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

Poor Variable Naming

quality Beginner
debt(d7/e3/b3/t3)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7), because while phpcs/phpmd can flag short names and length rules, judging whether $data or $result is meaningfully named requires human review.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3), since quick_fix is renaming variables — usually scoped to one function via IDE rename refactor, slightly more than a one-liner when the variable spans a function body.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3), because poor names within a function add reading cost in that file but don't ripple architecturally; applies_to is broad but the choice is per-variable, not load-bearing.

t3 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'minor surprise' (t3), grounded in the misconception that short names reduce clutter — a learnable gotcha but not a behavior-contradicting trap; code still runs as named.

About DEBT scoring →

Also Known As

variable names naming $data $result $tmp

TL;DR

Single-letter variables, cryptic abbreviations, or meaningless names like $data and $tmp — forcing readers to hold context in their head that the name should provide.

Explanation

Variable names should reveal intent: $userEmailAddress is better than $uea, which is better than $x. Single-letter names are acceptable only for conventional loop counters ($i, $j), caught exceptions ($e), and mathematical variables in algorithms. Boolean variables should read as statements: $isActive, $hasPermission. Collections should be plural: $users, $orderIds. Avoid $data, $result, $temp, $value — all of these describe any value and none of them.

Common Misconception

Short variable names reduce clutter — they reduce keystrokes, not clutter; the cognitive load of decoding $rsp, $usr, and $cnt is far greater than reading $response, $user, $count.

Why It Matters

A function using $d, $r, $t, and $v forces every reader to mentally execute the function to understand what each variable holds — well-named variables eliminate that overhead.

Common Mistakes

  • $data for any array or object — what data? $userData, $orderData, $apiResponse.
  • $result, $ret, $r for return values — name it after what it holds: $user, $invoice.
  • $temp, $tmp for intermediate values — if it exists long enough to name, name it meaningfully.
  • Numeric suffixes: $user1, $user2 — use $currentUser and $previousUser or an array $users[].

Code Examples

✗ Vulnerable
function proc(array $d): array {
    $r = [];
    foreach ($d as $i => $v) {
        $tmp = $v['n'] . ' ' . $v['e'];
        $r[] = ['s' => strtoupper($tmp)];
    }
    return $r;
}
✓ Fixed
function formatUserDisplayNames(array $users): array {
    $formatted = [];
    foreach ($users as $user) {
        $fullName = $user['firstName'] . ' ' . $user['lastName'];
        $formatted[] = ['displayName' => strtoupper($fullName)];
    }
    return $formatted;
}

Added 16 Mar 2026
Edited 22 Mar 2026
Views 21
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 2 pings T 1 ping F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 1 ping T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F
No pings yet today
No pings yesterday
Amazonbot 7 Perplexity 3 Unknown AI 2 ChatGPT 2 Ahrefs 1 Google 1
crawler 15 crawler_json 1
DEV INTEL Tools & Severity
🟢 Low ⚙ Fix effort: Low
⚡ Quick Fix
Rename single-letter variables (except loop counters), abbreviations, and names like $data, $temp, $info to describe what the variable actually holds in the current context
📦 Applies To
any web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
$d $tmp $arr $data $info $result used as variable names outside tiny scope; abbreviations $usr $ord $pg; $result used for completely different types in same function
Auto-detectable: ✓ Yes phpcs phpmd phpstan
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: High ✗ Manual fix Fix: Low Context: Function

✓ schema.org compliant