Error Reporting in PHP

Many beginners to PHP are not aware of errors that may be occurring, seemingly, invisibly. This is at fault of the default error reporting setting, which excludes both notice-level and strict-level errors, and at the fault of the display_errors directive that may be turned off. To know of all the errors that are occurring in your script, ensure to put these following statements at the very beginning of your script.

ini_set('display_errors', 'on');
error_reporting(E_ALL | E_STRICT);

These can also be set in php.ini and is recommended that you do so for display_errors. If you have display_errors off in php.ini, you will not see errors outputted to the browser that prevent your script from executing, such as parse errors. If your script never executes, the call to ini_set() will never happen and display_errors will never be set to on. Therefore, for development, it is always recommended to have display_errors configured to on in php.ini. Calling error_reporting(E_ALL | E_STRICT) during your script is fine, however, so long as you do it at the beginning.

Now go make some error-free code!


0 Responses to Error Reporting in PHP

  1. There are currently no comments.

Leave a Reply



About

User