Home > Article > Backend Development > How to display errors in PHP files?
A PHP application produces many levels of errors during the runtime of the script. So in this article, we will learn how to display all the errors and warning messages.
The quickest way to display all php errors and warnings is to add these lines to your PHP code file:
ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
The ini_set function will try to overwrite the configuration in the php.ini file. If display_error is turned off in the php.ini file, it will turn it on in the code. It also sets display_startup_errors to true to display error messages. error_reporting() is a native PHP function used to display errors. By setting it to true, it will show errors that occur in the code.
But another question arises, what is E_ALL? The answer is simple, PHP code generates errors at different levels. Let us understand the types of errors that occur in PHP code.
Unfortunately, the above code we wrote rarely shows parsing errors, such as missing semicolons or missing curly braces. In this case, the php.ini configuration must be modified.
display_errors = on
In the php.ini document, the display_errors directive must be set to "on". This will show all errors, including syntax or parsing errors, which cannot be shown by calling the ini_set function in PHP code.
So by the above way we can display errors in our php application.The above is the detailed content of How to display errors in PHP files?. For more information, please follow other related articles on the PHP Chinese website!