Solved: enable php error

Sure, I can write an article on enabling PHP errors for you, blending my programming knowledge and my writing skills. Here it is:

PHP, a popular scripting language designed for web development, is used worldwide to create dynamic interactive websites. Errors, however, are a part and parcel of any development process. While PHP is a very forgiving language, debugging could turn into a nightmare if errors remain unseen or unknown. One of the most effective tools for troubleshooting PHP issues is PHP’s own error reporting.

In a live environment, these errors are often hidden to prevent exposing sensitive information. However, while developing, it is critically important for those errors to be visible as it points the developers in the right direction to rectify them before pushing the code to production.

Enabling PHP Error Reporting

[b]Error reporting[/b] in PHP can be initiated by calling the function [b]error_reporting()[/b] in your code. This PHP function is used to set the error_reporting directive at runtime. Here’s the simple piece of code that’ll turn on all PHP errors, warnings, and notices:

ini_set('display_errors', 1);


  • error_reporting(E_ALL)
  • line ensures that all types of errors, including fatal errors, warnings, notices, etc., are reported.

  • The ini_set(‘display_errors’, 1) line is responsible for displaying those errors in your browser.

Understanding the Code

In the PHP language, there exist various levels of error reporting which can assist a developer in identifying different kinds of problems that may have happened during the code execution.

– E_ALL: It is the master value which includes all errors, warnings, and notices, irrespective of the severity.
– E_ERROR: This is used to indicate basic runtime errors which usually happens when some requirement to run the script cannot be met.
– E_WARNING: It indicates warnings, which are non-fatal. The script continues to run even after such errors
– E_PARSE: These errors are compile-time parse errors, generated by the parser when analyzing the code.
– E_NOTICE: These are runtime notices, which can indicate possible bugs, like accessing an undefined variable.

This makes it easier for developers to pinpoint exactly what’s causing an issue and how to resolve it.

Other methods to enable PHP error reporting

In addition to the above method of enabling PHP error reporting, you may also achieve the same through the PHP.ini file or through the .htaccess file.

// PHP.ini file
display_errors = On
error_reporting = E_ALL

// .htacces file
php_flag display_errors On
php_value error_reporting E_ALL

Keeping in mind the levels of error reporting, it’s obvious that robust and proper error handling is an integral part of PHP programming. With practice and experience, dealing with PHP errors gets easier and simpler, thus leading to more efficient and reliable web programming.

Related posts:

Leave a Comment