Home  >  Article  >  Backend Development  >  How to display errors in PHP files?

How to display errors in PHP files?

王林
王林forward
2023-08-19 20:41:19844browse

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.

  • E_ERROR:

    Fatal runtime error, execution of script has stopped
  • E_WARNING:

    Non-fatal runtime error, script Execution of
  • E_PARSE:

    Compile-time error, generated by the parser
  • E_NOTICE:

    The script found something that might be wrong
  • E_CORE_ERROR:

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

    Non-fatal error that occurred during the initial startup of the script
  • E_ALL:

    All Errors and Warnings
  • 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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete
Previous article:PHP Phar context optionsNext article:PHP Phar context options

Related articles

See more