Basics
PHP reports errors in response to a number of internal error conditions. These may be used to signal a number of different conditions, and can be displayed and/or logged as required.
Every error that PHP generates includes a type. A list of these types is available, along with a short description of their behaviour and how they can be caused.
Handling errors with PHP
If no error handler is set, then PHP will handle any errors that occur
according to its configuration. Which errors are reported and which are
ignored is controlled by the
error_reporting
php.ini directive, or at runtime by calling
error_reporting(). It is strongly recommended that the
configuration directive be set, however, as some errors can occur before
execution of your script begins.
In a development environment, you should always set
error_reporting
to E_ALL
, as you need to be aware of and fix the
issues raised by PHP. In production, you may wish to set this to a less
verbose level such as
E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
, but
in many cases E_ALL
is also appropriate, as it may
provide early warning of potential issues.
What PHP does with these errors depends on two further php.ini directives.
display_errors
controls whether the error is shown as part of the script's output. This
should always be disabled in a production environment, as it can include
confidential information such as database passwords, but is often useful to
enable in development, as it ensures immediate reporting of issues.
In addition to displaying errors, PHP can log errors when the
log_errors
directive is enabled. This will log any errors to the file or syslog
defined by
error_log
. This
can be extremely useful in a production environment, as you can log errors
that occur and then generate reports based on those errors.
User error handlers
If PHP's default error handling is inadequate, you can also handle many types of error with your own custom error handler by installing it with set_error_handler(). While some error types cannot be handled this way, those that can be handled can then be handled in the way that your script sees fit: for example, this can be used to show a custom error page to the user and then report more directly than via a log, such as by sending an e-mail.
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-language.errors.basics.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.