PHP Data Types Overview Quiz
A 40-question quiz covering how PHP represents scalars, arrays, objects, enums, and resources so teams can reason about conversions, validation, and storage when values move through an application.
Question 1
While preparing an orientation card for new hires, which list contains only PHP scalar types they will handle on their first week?
Question 2
A build pipeline logs this snippet while checking an import; what does it display?
<?php
$value = "42";
$value += 8;
var_dump($value);
?>Question 3
Product analytics needs reassurance that counters remain exact. Why are integers the preferred storage for page-view totals?
Question 4
A teammate enables strict typing before this helper to stabilize metrics. What happens when it runs?
<?php
declare(strict_types=1);
function sumIntegers(int $a, int $b): int {
return $a + $b;
}
echo sumIntegers('3', 2);
?>Question 5
A support dashboard compares the string "007" with the number 7. Which operator keeps them distinct so the alert only fires on truly identical values?
Question 6
QA shares this snippet to illustrate floating-point behavior. What does it output?
<?php
$score = 0.1 + 0.2;
var_dump($score === 0.3);
?>Question 7
Finance automation stores invoice totals as strings and uses BCMath for arithmetic. Why choose this pattern over plain floats?
Question 8
A logging helper prints the type of incoming payloads. What does this snippet echo?
<?php
$data = ['status' => 'draft'];
echo get_debug_type($data);
?>Question 9
Architecture guidelines mention compound types. Which PHP values fall into that family?
Question 10
During an API debug session, what type does json_decode return by default for JSON objects?
<?php
$result = json_decode('{"count":5}');
echo gettype($result);
?>Question 11
A docstring marks a parameter as mixed. What does that communicate to anyone calling the function?
Question 12
A migration script uses settype to normalize seat counts. What does it echo?
<?php
$value = '9 seats';
settype($value, 'int');
echo $value;
?>Question 13
When documentation references a resource type, what does that label mean in PHP?
Question 14
Ops opened a temporary memory stream to test logging. What does var_dump show?
<?php
$handle = fopen('php://memory', 'r');
var_dump($handle);
?>Question 15
A job queue stores callbacks for retries. Why does the interface demand that each entry be callable?
Question 16
A teammate checks whether arrow functions satisfy the callable contract. What does this snippet output?
<?php
$handler = fn (int $n): int => $n * 2;
var_dump(is_callable($handler));
?>Question 17
Why do typed properties on DTOs make code reviews calmer when discussing expected data types?
Question 18
The data platform introduces a union-typed normalizer. What gets printed?
<?php
class Normalizer {
public function magnitude(int|float $value): float {
return abs($value);
}
}
echo (new Normalizer())->magnitude(-4.5);
?>Question 19
A profile form stores an optional nickname. Why would the DTO declare the property as ?string instead of plain string?
Question 20
A DTO starts with a null typed property and relies on a fallback. What does this snippet echo?
<?php
class ToggleDTO {
public ?bool $enabled = null;
}
$dto = new ToggleDTO();
echo $dto->enabled ?? 'unset';
?>Question 21
Why would a team choose SplFixedArray when modelling a week of hourly samples?
Question 22
A legacy API expects arrays, so a teammate casts an object first. What does the printout look like?
<?php
$user = (object) ['name' => 'Lea'];
print_r((array) $user);
?>Question 23
Product managers defined a closed list of publishing phases. How do enums help with data types in this situation?
Question 24
A backed enum powers deployment gates. What does this snippet echo?
<?php
enum Phase: string {
case Draft = 'draft';
case Live = 'live';
}
echo Phase::Live->value;
?>Question 25
Input validation uses filter_var($input, FILTER_VALIDATE_INT). What makes this helpful for data types?
Question 26
A warehouse script checks SKU strings before casting. What prints?
<?php
echo ctype_digit('042') ? 'digits' : 'mixed';
?>Question 27
A CLI importer reads hexadecimal identifiers. When would intval($token, 16) be preferred over a simple (int)$token cast?
Question 28
An ETL step casts a label before storing it. What echoes to the console?
<?php
$value = (int) '15apples';
echo $value;
?>Question 29
A permission check uses in_array($role, $allowed, true). Why insist on the strict flag?
Question 30
A data-cleaning pass keeps only integers from a mixed array. What does it print?
<?php
$values = ['3', 'level', 2];
$result = array_filter($values, 'is_int');
print_r($result);
?>Question 31
Why might a scheduling module favor DateTimeImmutable over DateTime for representing appointments?
Question 32
A monitoring script classifies values by type. What does it echo?
<?php
$value = 5.5;
echo match (get_debug_type($value)) {
'int' => 'whole',
'float' => 'decimal',
default => 'other'
};
?>Question 33
Log aggregation recently switched from gettype to get_debug_type. What advantage does the newer helper provide when diagnosing data mismatches?
Question 34
During API design, why differentiate between null and an empty string when representing an optional nickname?
Question 35
When normalizing boolean toggles from HTML forms, why use filter_var with FILTER_VALIDATE_BOOL and FILTER_NULL_ON_FAILURE?
Question 36
Static analysis rules request docblocks such as @var array<int, string>. How does that help with data types?
Question 37
Finance code wraps raw integers inside a Money value object. What benefit does that bring to type handling?
Question 38
A DTO marks several properties as readonly. How does that choice relate to data-type safety?
Question 39
Why do architects discourage storing resources or open stream handles inside sessions or caches?
Question 40
An ingestion Lambda receives numeric strings from partners. Why cast them to int or float before arithmetic even if PHP would juggle them automatically?
