Displaying Errors

One of the very first issues that arise when it comes to debugging PHP scripts is that you may or may not even see the errors that occur. After you install PHP on a Web server, it will run under a default configuration with respect to security, performance, how it handles data, and so forth. One of the default settings is to not display any errors. In other words, the display_errors setting will be off. When that’s the case, what you might see when a script has an error is a blank page. (This is the norm on fresh installations of PHP; most hosting companies will enable display_errors.)

The reason that errors should not be displayed on a live site is that it’s a security risk. Simply put, PHP’s errors often give away too much information for the public at large to see (not to mention showing PHP errors looks unprofessional). But you, the developer, do need to see these errors in order to fix them!

So, to ensure that no errors are displayed on a live site, just enter this line in every page of the site:


The ini_set() function allows a script to temporarily override a setting in PHP’s configuration file (many, but not all, settings can be altered this way).

Make sure that you call it first thing in your PHP section so the rest of the PHP code will abide by this new setting.