Poor Variable Naming
debt(d7/e3/b3/t3)
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.
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.
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.
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.
Also Known As
TL;DR
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
Why It Matters
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
function proc(array $d): array {
$r = [];
foreach ($d as $i => $v) {
$tmp = $v['n'] . ' ' . $v['e'];
$r[] = ['s' => strtoupper($tmp)];
}
return $r;
}
function formatUserDisplayNames(array $users): array {
$formatted = [];
foreach ($users as $user) {
$fullName = $user['firstName'] . ' ' . $user['lastName'];
$formatted[] = ['displayName' => strtoupper($fullName)];
}
return $formatted;
}