How to display errors in PHP files?

王林
Release: 2023-08-19 20:42:02
forward
765 people have browsed it

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);
Copy after login

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
    Copy after login

    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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!