Dr. Logan | COM Courses | Syllabus | Reading Notes

Programming errors:

Dumping variables as a debugging aid: Listing 25.1 (p. 531-2) will dump the contents of the POST, GET, SESSION, and COOKIES arrays, allowing you to check form and state variables.

Error Reporting Settings in PHP: The level of error reporting is det by default in php.ini (see p. 524). For our class, we've set it to include some low level (minor) errors, which may cause an occasional pain but which encourages tighter code as we learn. That is, we 1)report all errors except notices, 2)output error messages as html, 3) log no messages to the server disk, and 4) track no errors. The level of reporting is set by using constants, listed in table 25.1; these can be combined, as shown on p. 534. For example, the constant E_ERROR reports fatal errors at runtime, E_WARNING reports nonfatal errors at runtime, and E_PARSE reports parse errors.

You can turn the error reporting off, so that they don't show on the html of a production site, and turn the logging on, so that you can look at the log for errors without affecting the html stream. Change these using error_reporting(), which is passed one of the error reporting constants listed in table 25.1, temporarily altering the default error reporting setting.

Graceful error handling: One way to deal with errors is to set up exception handlers, which is covered in chapter 7. Listing 25.2 provides a way to customize error messages using the error number returned by php by referring the error constant to your own error handling function, called by set_error_handler('my_own_handler'); This function must have the syntax my_error_handler (int error_type, string error_msg [, string errfile [, int errline [, array errcontext]]])).