PHP Error Handling Levels Quiz
A 35-question quiz that demystifies PHP error reporting levels, display/log configuration, custom handlers, and production-safe diagnostics with 11 practical code checks.
Question 1
Why do production stacks usually set display_errors=Off even though development machines keep it On?
Question 2
What does this snippet echo?
<?php
error_reporting(E_ERROR | E_PARSE);
echo (error_reporting() & E_WARNING) ? 'warn' : 'quiet';
?>Question 3
Why does error_reporting(E_ALL) remain a recommended baseline even when a framework filters logs?
Question 4
A DevOps engineer toggles error_reporting via ini_set inside bootstrap code. Why add a comment referencing php.ini as well?
Question 5
What does this snippet print?
<?php
set_error_handler(function () {
echo 'handled';
});
trigger_error('test', E_USER_WARNING);
?>Question 6
Why should error_log messages include request IDs or correlation tokens?
Question 7
What does this snippet output when display_errors is On?
<?php
set_error_handler(function ($level, $message) {
echo strtoupper($message);
});
$value = $undefined + 1;
?>Question 8
Why does the @ operator hide errors only if they occur in the same expression?
Question 9
What does this configuration snippet echo?
<?php
ini_set('log_errors', '1');
ini_set('error_log', __DIR__ . '/var/app.log');
echo ini_get('log_errors');
?>Question 10
Why do SRE teams centralize PHP error logs via syslog or log shipping agents?
Question 11
What does this snippet output?
<?php
error_reporting(E_ALL & ~E_DEPRECATED);
echo (error_reporting() & E_DEPRECATED) ? 'on' : 'off';
?>Question 12
Why should applications escalate E_USER_ERROR events cautiously?
Question 13
What does this snippet echo?
<?php
$previous = set_error_handler(function () {
echo 'first';
});
set_error_handler(function () {
echo 'second';
});
restore_error_handler();
trigger_error('oops', E_USER_NOTICE);
?>Question 14
Why do QA environments often mirror production error_reporting masks but keep display_errors On?
Question 15
What does this snippet output?
<?php
register_shutdown_function(function () {
$error = error_get_last();
echo $error ? $error['type'] : 'clean';
});
strpos();
?>Question 16
Why do teams categorize E_DEPRECATED separately from E_WARNING?
Question 17
What does this snippet echo?
<?php
ini_set('error_prepend_string', '<strong>');
ini_set('error_append_string', '</strong>');
trigger_error('formatted', E_USER_WARNING);
?>Question 18
Why should log rotation consider PHP-FPM pool restarts?
Question 19
What does this snippet emit?
<?php
try {
set_error_handler(function ($errno, $errstr) {
throw new ErrorException($errstr, 0, $errno);
});
$x = $undefinedVar + 1;
} catch (Throwable $e) {
echo $e->getMessage();
}
?>Question 20
Why do incident reports include the exact error level along with stack trace excerpts?
Question 21
What does this snippet output?
<?php
error_reporting(E_ALL);
set_error_handler(function ($errno) {
if ($errno === E_NOTICE) {
echo 'notice';
return true;
}
});
$value = $undefined + 1;
echo 'done';
?>Question 22
Why do platform teams audit php.ini for xdebug.default_enable before promoting builds?
Question 23
What does this snippet echo?
<?php
error_reporting(0);
echo (int) error_reporting();
?>Question 24
Why is logging E_USER_NOTICE helpful even if the application continues functioning?
Question 25
Why would a custom error handler return false after logging a notice?
Question 26
Why do code reviews flag uses of die($message) in library code?
Question 27
Why do bootstrap scripts register set_exception_handler in addition to set_error_handler?
Question 28
Why should display_startup_errors stay Off in production even if logs capture startup failures?
Question 29
What makes E_RECOVERABLE_ERROR different from E_ERROR?
Question 30
Why might teams raise log_errors_max_len when sending stack traces to syslog?
Question 31
Why call error_clear_last() after inspecting error_get_last() inside cleanup code?
Question 32
Why do CLI operators sometimes pass -derror_reporting when running maintenance scripts?
Question 33
Why keep E_USER_WARNING metrics separate from E_WARNING metrics?
Question 34
Why do API responses leave html_errors Off even in staging?
Question 35
Why do runbooks document the expected error_reporting value for each environment?
