PHP Error Handling and Debugging (Professional Basics)
Learn how to read errors, show them in dev, hide them in production, and debug faster.
Daniel Price
September 28, 2025
6.8k334
Errors are normal. The goal is to understand them quickly and fix with confidence.
Turn on errors in development
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
Use this in local/dev only, not production.
Common debugging tools
var_dump()
var_dump($user);
print_r()
print_r($arr);
die() / exit()
die("Stop here");
Production rule
In production:
- do not show errors to users
- log them instead
ini_set('display_errors', '0');
ini_set('log_errors', '1');
ini_set('error_log', __DIR__ . '/php-error.log');
Next: JSON, APIs, and handling modern web data.
#PHP#Debugging#Beginner