PHPPHP15 min read

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
December 21, 2025
0.0k0

Errors are normal. The goal is to understand them quickly and fix with confidence.

Turn on errors in development

```php 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() ```php var_dump($user); ```

### print_r() ```php print_r($arr); ```

### die() / exit() ```php die("Stop here"); ```

Production rule

In production: - do not show errors to users - log them instead

```php 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