On a developer's PC the error message should be shown in the full detail, along with other useful information, to ease the development process.To configure error reporting the right way, one should always follow these two cornerstone rules: Only by the time your code goes live you will need some error handling code but that could be a short code snippet that would handle all errors the uniform and centralized way. Instead, just configure PHP to report errors by itself. To put it short: write your scripts without any dedicated error reporting code. Only as a last resort set them right in the script using ini_set() command: error_reporting ( E_ALL ) īut it will fail for some errors (parse errors for example).Īnd then create an error handler for a live site that is showing an excuse page in case of PHP error. for php-fpm it should be set in the corresponding.for PHP CGI it should be set in the local php.ini file.for the Apache's mod_php it should be set in nf or.Note that these values are better to be set in php.ini or in the the server's configuration: error_reporting should be set to E_ALL value.And then, configure PHP to direct these messages appropriately: on a dev server they have to be shown on-screen whereas on a live server they should be logged while only a generalized error page without any particular details should be shown to a site visitor. Instead, make PHP generate errors by itself. Below you will find a set of basic principles that will help you to satisfy such contradicting demands, as well as their complete practical implementation TL DRĪs a rule, do not add error reporting operators to your PHP code (especially ones that output the error message right to the screen). The exact moment you'll have these things sorted out, you'll know what to do with error messages in PHP. a regular site user who must see not a single error message, but rather a generic excuse page instead.a programmer who needs to see every error possible with every minute detail provided.As a result, the error reporting is often inflexible, hard to maintain, not user-friendly or even harmful.Īll the confusion is coming from the fact that every site has two kinds of customers: a programmer and a user, who require totally different treatment in regard of error messages: The complete error handling example codeĭue to various historical reasons, there are thousands of bad practices in the area of error handling and reporting.What if some function refuses to raise an error?.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |