PHP Variable Naming Quiz
A 35-question quiz devoted to PHP variables, naming conventions, scope rules, references, and the small habits that keep data easy to follow across templates, services, and background jobs.
Question 1
While wiring a shipping dashboard, which variable name safely represents the number of parcels loaded today without violating PHP identifier rules?
Question 2
A teammate double-checks whether case sensitivity matters. What does this snippet output?
<?php
$count = 4;
echo $Count ?? 0;
?>Question 3
During a design system review, which boolean naming style communicates intent most clearly to other engineers?
Question 4
A junior dev wonders whether functions see outer variables automatically. What does this snippet echo?
<?php
$total = 7;
function addOne() {
$total = 1;
}
addOne();
echo $total;
?>Question 5
During a payroll audit, why is `$hoursWorkedThisWeek` preferred over `$hw` for long-lived variables?
Question 6
A bug hunt involves references. What does this snippet output?
<?php
$region = 'north';
$alias =& $region;
$alias = 'south';
echo $region;
?>Question 7
In an object-oriented codebase, what does `$this` represent when used inside a class method?
Question 8
A cleanup script removes temporary values. What does the snippet print?
<?php
$userName = 'Rafi';
unset($userName);
echo isset($userName) ? 'set' : 'cleared';
?>Question 9
When storing multiple orders in an array, why do teams prefer plural names such as `$orders` over `$orderListThing` or `$o`?
Question 10
A utility function tracks clicks. What appears in the output buffer?
<?php
function tapCounter() {
static $count = 0;
$count += 2;
return $count;
}
echo tapCounter();
echo tapCounter();
?>Question 11
Why do most style guides keep constant names such as `MAX_UPLOAD_SIZE` in uppercase?
Question 12
A finance helper needs to adjust a shared rate. What does this snippet echo?
<?php
$rate = 1.2;
function adjustRate() {
global $rate;
$rate += 0.1;
}
adjustRate();
echo $rate;
?>Question 13
Code reviewers often allow single-letter variables only inside short loops. Why the restriction?
Question 14
A teammate experiments with array destructuring. What gets echoed?
<?php
$pair = ['make', 'model'];
[$first, $second] = $pair;
echo $second;
?>Question 15
Billing code stores currency in cents. Why name the variable `$priceCents` instead of `$price`?
Question 16
A support script wants a fallback alias. What happens here?
<?php
$alias = null;
$alias ??= 'guest';
echo $alias;
?>Question 17
When injecting dependencies, why pair a descriptive variable like `$emailSender` with the type-hinted interface?
Question 18
An old plugin used variable variables. What does this snippet echo?
<?php
$field = 'status';
$status = 'active';
echo $$field;
?>Question 19
Configuration files often prefix environment variables with `ENV_` or `APP_`. Why keep that convention?
Question 20
When documenting a helper function, why should parameter names in the docblock match the actual signature?
Question 21
A closure needs a label defined outside. What does this snippet echo?
<?php
$prefix = 'srv';
$builder = function () use ($prefix) {
return $prefix . '-01';
};
echo $builder();
?>Question 22
What is the practical difference between using `global $config;` inside a function and reading `$GLOBALS['config']` directly?
Question 23
During a null-check tutorial, what does this snippet output?
<?php
$value = null;
echo isset($value) ? 'set' : 'missing';
?>Question 24
Why should developers avoid reusing a variable for entirely different meanings later in the same function?
Question 25
A responder packages a payload. What structure is produced?
<?php
$team = 'ops';
$role = 'lead';
$bundle = compact('team', 'role');
echo $bundle['team'] . ':' . $bundle['role'];
?>Question 26
In a value object storing addresses, why keep property names like `$streetLine1` instead of generic terms such as `$fieldOne`?
Question 27
When logging metrics, why distinguish between `$requestDurationMs` and `$requestDurationSeconds` rather than reusing one variable?
Question 28
A legacy template still uses extract(). What does this snippet echo?
<?php
$data = ['title' => 'Docs', 'status' => 'draft'];
extract($data);
echo $status;
?>Question 29
Why is it useful to prefix feature-flag variables (for example, `$ffCheckoutDiscount`) when multiple experiments coexist?
Question 30
When a variable does something non-obvious, why include a quick inline comment explaining the intent?
Question 31
A product export destructures associative data. What prints here?
<?php
$user = ['id' => 9, 'name' => 'Ivy'];
['id' => $userId] = $user;
echo $userId;
?>Question 32
Why must superglobal names such as `$_POST` stay uppercase when referenced?
Question 33
In multilingual applications, why include locale hints in variable names such as `$dateFr` versus `$dateEn`?
Question 34
Why is `$temporaryToken` a better name than `$token2` when holding a one-time password during signup?
Question 35
When teaching interns, why emphasize aligning variable names with the business glossary kept by product managers?
