How to display errors in PHP file?


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 override the configuration found in your php.ini file. If in the php.ini file display_error is turned off it will turn that on in the code. It also set display_startup_errors to true to show the error message. error_reporting() is a native PHP function that is used to display the errors. By setting it true it displays the error that occurs in the code.

But there is an again question arises what is E_ALL? The answer is simple PHP code produces different levels of errors. So let's learn what are those types of errors occurs in a PHP code.

  • E_ERROR :

    fatal runtime error execution of script has been halted
  • E_WARNING :

    nonfatal runtime error execution of script has been halted
  • E_PARSE :

    compile time error it is generated by the parser
  • E_NOTICE :

    The script found something that might be an error
  • E_CORE_ERROR :

    Fatal errors that occurred during the initial startup of script
  • E_CORE_WARNING :

    Nonfatal errors that occurred during the initial startup of script
  • E_ALL :

    All errors and warning
  • Unfortunately, the above code we have composed won't almost certainly show parse errors, for example, missing semicolons or missing wavy supports. For this situation, the php.ini setup must be altered.

    display_errors = on

    The display_errors order must be set to "on" in the php.ini document. This will show every one of the errors including syntax or parse mistakes that can't be shown by simply calling the ini_set work in the PHP code.

    So in the above way, we can display errors in our php application.

Updated on: 07-Oct-2023

32K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements