Chapter 22. Error Handling

In this lesson you will learn how to deal with errors in PHP scripts effectively and how to debug code that does not work as you expect them to.

Error Reporting

PHP has a configurable error reporting system that you can set to be just as pedantic you want it to be about code. By default, the strictest mode is not enabled, and, in most cases, you get a warning message only when an imperfection has a good chance of affecting the intended purpose of your script.

Changing Error Levels

To change the error reporting level, you use the error_reporting function with a value that is made up of the constants shown in Table 22.1.

Table 22.1. Error Reporting Constants

Constant

Description

E_ERROR

Indicates a fatal runtime error. Script ...

Get Sams Teach Yourself PHP in 10 Minutes now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.